Please help me understand why the following doesn't work.
In particular - instance attributes of a tested class are not visible to Python's unittest.Mock
.
In the example below bar
instance attribute is not accessible.
The error returned is:
AttributeError: <class 'temp.Foo'> does not have the attribute 'bar'
import unittest
from unittest.mock import patchclass Foo:def __init__(self):super().__init__(self)self.bar = some_external_function_returning_list()def do_someting(self):calculate(self.bar)class TestFoo(unittest.TestCase):@patch('temp.Foo.bar')def test_do_something(self, patched_bar):patched_bar.return_value = ['list_elem1', 'list_elem2']