pytest "fixture not found" in CI
A test function named a fixture in its arguments, but pytest found no fixture by that name in scope. The fixture may live in a conftest that does not apply, come from an uninstalled plugin, or be misspelled.
What this error means
pytest errors with "fixture 'db_session' not found" and lists the fixtures it does know about, suggesting close matches.
pytest
E fixture 'db_session' not found
> available fixtures: cache, capfd, capsys, monkeypatch, tmp_path, ...
> use 'pytest --fixtures [testpath]' for help on them.Common causes
The fixture is defined in an out-of-scope conftest
A fixture in a conftest.py that does not cover the test's directory is not visible to it.
A plugin providing the fixture is not installed
Fixtures like db_session may come from a pytest plugin missing in the CI environment.
How to fix it
Place the fixture where tests can see it
- Move shared fixtures into a
conftest.pyat or above the test directory. - Or install the plugin that provides the fixture.
- Run
pytest --fixturesto confirm it is now discoverable.
Terminal
pytest --fixtures tests/Install the fixture-providing plugin
Add the plugin to your dev dependencies so its fixtures register.
Terminal
pip install pytest-postgresqlHow to prevent it
- Keep shared fixtures in a top-level
conftest.py. - Install all pytest plugins your tests rely on in CI.
- Use
pytest --fixturesto audit available fixtures.
Related guides
pytest "ImportError while importing test module" in CIFix pytest "ImportError while importing test module" in CI - a test file failed to import, often from a dupli…
pytest marker not registered (--strict-markers) in CIFix pytest "Unknown marker" under --strict-markers in CI - a custom marker is used but not declared, so stric…
pytest ModuleNotFoundError during collection in CIFix a pytest ModuleNotFoundError during collection in CI - pytest cannot import your package while loading te…