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, teardownmust revert the decorator.
- pytestfixture with finalizer
- pytestfixture with- yieldexpression.
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.