How to make `@decorator` with other decorators?
brno32 opened this issue · 3 comments
brno32 commented
The following code snippet
@decorator
@responses.activate
def mock_api(func, *args, **kwargs):
responses.add(
responses.GET,
EXAMPLE_API,
json={"success": True},
)
result = func(*args, **kwargs)
return result
@mock_api()
def test_api_call():
requests.get(EXAMPLE_API)
generates the following error
TypeError: test_api_call() takes 0 positional arguments but 1 was given
Is there a way to combine @decorator
with a decorator from another library to build my own super decorator?
micheles commented
Yes, try to invert the order:
@responses.activate
@decorator
def mock_api(func, *args, **kwargs):
...
brno32 commented
Thanks for the suggestion! That seems to fix the error above. This may be more of a question about how responses works, but switching the order seems to invalidate responses and it fails to mock the call
brno32 commented
This problem seemed to solve itself by upgrading both responses
and decorator
to their latest version