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.
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.
pytest --fixtures tests/Install the fixture-providing plugin
Add the plugin to your dev dependencies so its fixtures register.
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.