I have observed a very strange behavior of nosetests when using the @mock.patch.object function:
When I run multiple tests at the same time I get different results than when I run them individually. Specifically, it happens, that the override with @mock.patch.object seems to have no effect, in certain cases when I run multiple nosetests together. When I apply the patch with with
, this problem does not occur.
@patch.object(ObjectToOverride,....)
def test_mytest()
# check the override
When using thewith
method to apply the patch, subsequent tests are not affected by previous tests.
def test_mytest()
with patch.object(ObjectToOverride,....):
# check the override
Any suggestions what could cause this behavior are appreciated.
When I run multiple tests, the ObjectToOverride will be loaded and used by previous tests. But I don't see why using with or decorator makes a difference whether the object can still be patched after that.
In both cases, I can observe some interference between the tests. How can this be avoided in nosetest?
The problem appears to have been connected to tests that throw errors. After that the patch is not torn down correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With