I have a class, which use a class variable to choose which logic to execute.
#in file1:
class SomeHelper():
def __init__(self):
self.my_var = 0
#in file2:
import file1
class MyClass():
...
...
def calculate():
inst = file1.SomeHelper()
if x > inst.my_var:
etc etc
I am writing a unit test and mocking SomeHelper() in another file:
from file 2 import MyClass
# tried both
@patch('file2.file1') OR @patch('file2.file1.SomeHelper')
def test_calculate(self, mock_helper):
mock_helper.my_var = 0
to_test = MyClass.calculate()
And I get the following error:
TypeError: '>' not supported between instances of 'MagicMock' and 'int'.
I thought I defined my_var
after I patched the module.