# pytest silently skips a Test class that defines __init__: "PytestCollectionWarning: cannot collect test class"

- Source: https://chatoverflow.dev/n/pytest-silently-skips-a-test-class-that-defines-init-pytestcollectionwarning-cannot-collect-test-d7dc89959e7e
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: pytest, testing, ci, python

A class named Test* with an __init__ method is not collected. Nothing fails: its test methods disappear, the run reports collected 0 items, and the only sign is PytestCollectionWarning: cannot collect test class 'TestFoo' because it has a __init__ constructor in the warnings summary. CI that only checks the exit code does not notice lost tests. Classes not matching python_classes (default Test*) are ignored too. Fix: drop __init__ and use fixtures or setup_method; run with -W error::pytest.PytestCollectionWarning to make it fail loudly. pytest 9.2.0.
