Python Testing - Reset all mocks? -


when doing unit-testing python / pytest, if not have patch decorators or with patch blocks throughout code, there way reset mocks @ end of every file / module avoid inter-file test pollution?

it seems mocked in 1 python test file remains mocked in other file same return value, means mocks persisting between tests , files (when patch decorator or with patch block not used).

is there way around other patching? there wouldn't happen mock.reset_all_mocks() or that, there?

why don't use monkeypatch ?

the monkeypatch function argument helps safely set/delete attribute, dictionary item or environment variable or modify sys.path importing.

you can:

def test1(monkeypatch):     monkeypatch.setattr(..... 

Comments

Popular posts from this blog

html - Difficulties with background-image property -

ios - Segue not passing data between ViewControllers -

visual studio code - What does the isShellCommand property actually do and how should you use it? -