Python Testing - Reset all mocks?

后端 未结 3 1274
情书的邮戳
情书的邮戳 2021-02-09 11:05

When doing unit-testing with Python / PyTest, if you do you not have patch decorators or with patch blocks throughout your code, is there a way to reset all mocks a

3条回答
  •  失恋的感觉
    2021-02-09 11:35

    why don't use monkeypatch ?

    The monkeypatch function argument helps you to safely set/delete an attribute, dictionary item or environment variable or to modify sys.path for importing.

    you can:

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

提交回复
热议问题