You have to control complete lifecycle of your mocked decorator and revert the decorator back to original state.
It can be done in few different ways:
- context manager which builds the mocked decorator, and reverts it back by
__exit__.
- setup and teardown functions for your test,
teardown must revert the decorator.
pytest fixture with finalizer
pytest fixture with yield expression.
Personally I like the @pytest.yield_fixture as it keeps the code short and as soon as you realize, that all what comes after yield statement in the fixture code is cleanup code, things are very clear to do.