In python, mocking an object using
@patch('foo.bar')
def test_things(self, bar):
bar.return_value= ...
requires that all tested classes use
import foo
and can not use
from foo import bar
In the second case code under test uses the original object, as mock patches names rather than the function itself. This feels very brittle.
How do we write mocks which will work with both forms of import?