Provide a py.test fixture in addition to the decorator
See original GitHub issueWhen 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:
def test_my_api(responses):
responses.add(responses.GET, 'http://twitter.com/api/1/foobar',
body='{"error": "not found"}', status=404,
content_type='application/json')
# ...
I.e. instead of the decorator you’d use a responses
fixture and instead of calling add
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 module responses
, but a wrapper would be cleaner of course).
Issue Analytics
- State:
- Created 9 years ago
- Reactions:7
- Comments:8 (2 by maintainers)
Top Results From Across the Web
pytest fixtures: explicit, modular, scalable
Software test fixtures initialize test functions. They provide a fixed baseline so that tests execute reliably and produce consistent, repeatable, results.
Read more >How do I make pytest fixtures work with decorated functions?
Creating the decorator using the decorator package seems to do the trick. ... Fixture feature depends on test function signature.
Read more >Fixtures and Parameters: Testing Code with Pytest - Medium
The first and easiest way to instantiate some dataset is to use pytest fixtures. pytest.fixture decorator makes it possible to inject the return ......
Read more >End-To-End Tutorial For Pytest Fixtures With Examples
Along with parameterized test fixtures, pytest also provides decorators using which you can parameterize test functions.
Read more >Five Advanced Pytest Fixture Patterns - Inspired Python
The pytest package is a great test runner, and it comes with a battery of features — among them the fixtures feature. A...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Since pytest 3.0
yield_fixture
is deprecated in favour of usingfixture
directly: http://doc.pytest.org/en/latest/yieldfixture.htmlie:
Or even more simply:
Should we add this to the README?