There are many places in our test code where we do the following:
foo = Foo()
foo.bar = mocker.MagicMock()
We should make the following changes so that errors are raised if we mock non-existent attributes:
foo = Foo()
mock_bar = mocker.patch.object(foo, "bar")
# tests go here
...
assert mock_bar.called
The final assert also allows us to check that a mock was used. These two changes will help us keep our test suite tight so that there is not drift between the mocks we use in the tests and the calls made in the actual code.
Leaving open for now - intent is to reduce used of mocks wherever we can. It might be worth doing a pass through tests and eliminating the former pattern altogether.
There are many places in our test code where we do the following:
We should make the following changes so that errors are raised if we mock non-existent attributes:
The final assert also allows us to check that a mock was used. These two changes will help us keep our test suite tight so that there is not drift between the mocks we use in the tests and the calls made in the actual code.