fixture scope
How long pytest keeps one fixture value before building a new one: per test function, class, module, package or whole session.
In more detail
Function scope is the default and gives every test a fresh value. Widen the scope only to save real cost, such as starting a database container, and only for values nobody modifies; a shared mutable fixture makes test results depend on run order.
Example
@pytest.fixture(scope="module")Related terms
- fixture — A named piece of setup, defined with @pytest.fixture, that a test receives by listing the fixture's name as a parameter.
- shared mutable state — Data that several tests or requests can both read and change, so one can affect another.
- test isolation — The property that each test sets up everything it needs and leaves nothing behind, so tests pass in any order.
Taught in
- Fixtures And Their Scope — Automated Testing, TDD & Quality Engineering
- Testing The Filesystem — Automated Testing, TDD & Quality Engineering
- Testing With Real Databases — Automated Testing, TDD & Quality Engineering