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

Taught in

References