pytest "collected 0 items / 1 error" in CI
pytest tried to import a test module and that import raised, so it collected zero tests and reported a collection error. The real failure is the import error shown in the errors section, not a failing assertion.
What this error means
The summary reads collected 0 items / 1 error (or N items / 1 error), with an ERRORS section showing the import that failed. Because collection errored, the affected module contributed no tests.
==================== ERRORS ====================
____________ ERROR collecting tests/test_api.py ____________
ImportError while importing test module 'tests/test_api.py'.
...
ModuleNotFoundError: No module named 'app.services'
=========== 0 items collected / 1 error ===========Common causes
A test module fails to import
An import at the top of a test file (a missing dependency, a renamed module, or a first-party package not installed) raises during collection, so pytest cannot gather its tests.
A syntax or import-time error in the module
A SyntaxError or an exception raised at module import time prevents collection of that file entirely.
How to fix it
Fix the import shown in the errors section
- Read the
ERROR collecting ...block - it names the file and the import that failed. - Install the missing dependency, or
pip install -e .so first-party imports resolve. - Re-run; once the import succeeds, the module’s tests are collected.
Reproduce the import directly
Importing the test module in isolation surfaces the same error faster.
python -c "import tests.test_api"
pip install -e . # if it is a first-party importHow to prevent it
- Install the project (
pip install -e .) so test imports resolve in CI. - Keep test dependencies declared and installed alongside the app.
- Run a quick import smoke check before the full suite.