Python Testing - Reset all mocks?

后端 未结 3 1272
情书的邮戳
情书的邮戳 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:23

    After monkey-patching, I'm undoing it at the end of the test to avoid any leaking to other tests or limit the patching within the scope.

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

提交回复
热议问题