New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a py.test fixture in addition to the decorator #47
Comments
👍 |
1 similar comment
👍 |
Have not tested it in all situations yet, but this works for me: # conftest.py
import pytest
from responses import mock
@pytest.yield_fixture
def responses():
rsps = mock
rsps.start()
yield rsps
rsps.stop()
rsps.reset() |
Seems like a good start; how to make it obvious/deterministic where to call I suppose we could KISS and put both items just in an example in the README, eh? |
👍 |
Or even more simply: @pytest.yield_fixture
def responses():
with responses.RequestsMock() as rsps:
yield rsps Should we add this to the README? |
A README addition makes sense |
Since pytest 3.0 ie: @pytest.fixture
def responses():
with responses.RequestsMock() as rsps:
yield rsps |
When using py.test for tests it's usually nicer to activate features like this using a fixture. The usage with the fixture (assuming it's named
responses
) could be like this:I.e. instead of the decorator you'd use a
responses
fixture and instead of callingadd
as a global from the imported module (if you register it as a pytest plugin the user doesn't need to import it at all) you'd call it on the object returned by the fixture function (which could simple be the moduleresponses
, but a wrapper would be cleaner of course).The text was updated successfully, but these errors were encountered: