Review
In this chapter, we covered a lot about fixtures:
-
Fixtures are @pytest.fixture() decorated functions.
-
Test functions or other fixtures depend on a fixture by putting its name in their parameter list.
-
Fixtures can return data using return or yield.
-
Code before the yield is the setup code. Code after the yield is the teardown code.
-
Fixtures can be set to function, class, module, package, or session scope. The default is function scope. You can even define the scope dynamically.
-
Multiple test functions can use the same fixture.
-
Multiple test modules can use the same fixture if it’s in a conftest.py file.
-
Multiple fixtures at different scope can speed up test suites while maintaining test isolation.
-
Tests and fixtures can use multiple fixtures. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access