Running multiple tests interferes with nosetests when patched with @ mock.patch.object, and sometimes with `with mock.patch.object`

I observed a very strange behavior of the nets when using the @ mock.patch.object function:

When I run several tests at the same time, I get different results than when I run them separately. In particular, it happens that overriding with @ mock.patch.object does not seem to have an effect, in some cases, when I run several media networks together. When I apply a patch with with , this problem does not occur.

 @patch.object(ObjectToOverride,....) def test_mytest() # check the override 

When using the with method to apply a patch, subsequent tests do not affect previous tests.

 def test_mytest() with patch.object(ObjectToOverride,....): # check the override 

Any suggestions that may cause this behavior are appreciated.

When I run some tests, ObjectToOverride will be loaded and used by previous tests. But I don’t understand why using with or a decorator matters if this object can still be fixed after that.

In both cases, I can observe some interference between the tests. How can this be avoided in nosetest?

+5
source share
1 answer

The problem seems to be related to tests that cause errors. After that, the patch will not be properly broken.

+2
source

Source: https://habr.com/ru/post/1273631/


All Articles