February 2022
Intermediate to advanced
274 pages
6h 28m
English
Fixtures are often one of the trickier parts of pytest for people to get used to. Going through the following exercises will
Create a test file called test_fixtures.py.
Write a few data fixtures—functions with the @pytest.fixture() decorator—that return some data (perhaps a list, dictionary, or tuple).
For each fixture, write at least one test function that uses it.
Write two tests that use the same fixture.
Run pytest --setup-show test_fixtures.py. Are all the fixtures run before every test?
Add scope=’module’ to the fixture from Exercise 4.
Re-run pytest --setup-show ...
Read now
Unlock full access