class TestHoge():
def setup_class(cls, monkeypatch):
monkeypatch.setattr(target, 'TargetObj', MockObj)
Returns the following error:
TypeError: setup_class() missing 1 required positional argument: 'monkeypatch'
class TestHoge():
@pytest.fixture(autouse=True)
def patch(self, monkeypatch):
monkeypatch.setattr(target, 'TargetCls', MockCls)
def test_some_func(self):
ret = target.TargetCls().some_func()
By defining fixture in the test class and setting autouse = True
, monkey patch will be applied to all methods in the class.