Fixtures’ Scopes


Imad Dabbura


December 26, 2022

Fixtures are functions decorated by pytest.fixture() that run before/after test functions by pytest to do the setup/teardown. Test functions as well as other fixtures can depend on fixtures through their parameter list that would have the same name(s) of the fixture(s).

Scopes of fixtures:

A fixture can only depend on another fixture that is at the same scope level or wider. Also, for package/session scopes, the fixtures have to be defined inside that will be read by pytest before running tests in order to be actually at the package/session level; otherwise, they will default to the module.