I am trying to patch a decorator. The testing framework that I am using is pytest. I am able to patch it successfully. However, the patch remains through out the test session, and thus I am not able to test the decorator itself.
Here is a sample code
decorators.py
def decorator(resolver):
def wrap(*args, **kwargs):
kwargs.setdefault("additional_value", <some_value>)
return resolver(*args, **kwargs)
return wrap
patching the decorator
patch('decorators.decorator', decorator_mock).start()
I have tried stopping the patch as well. But this doesn't seem to work either
@pytest.fixture
def patch_reset_database_alias(request):
decorator_patch.stop()
importlib.reload(decorators)
def reset_patch():
decorator_patch.start()
request.addfinalizer(reset_patch)
I am not quite sure what is missing here, and how could I make it work.
Thanks