A test can sit under tests/unit/ with the right filename and still never run. If the parent command is python -m unittest discover -s tests, check whether the runner descends into unit/. A green OK line can appear while discovery runs only a top-level smoke test.

Check the count before trusting the final status.
Reproduce the skipped nested test
In an empty scratch directory, save this file as tests/unit/test_total.py:
import unittest
class TotalTest(unittest.TestCase):
def test_sum(self):
self.assertEqual(sum([2, 3]), 5)

The test file is in a subdirectory, not directly under the start directory.
Copy the file to tests/test_smoke.py too. That gives the runner one top-level test and one nested test. Run discovery from the scratch directory:
python -m unittest discover -s tests
On CPython 3.12.16, the relevant lines were:
Ran 1 test in 0.000s
OK

The process exits successfully even though it never runs the nested test.
Mark the nested test directory
The nested unit/ directory has no __init__.py. Create the empty marker and rerun the same command:
touch tests/unit/__init__.py
python -m unittest discover -s tests

The marker goes in the child directory that discovery skipped.
The relevant output now reads:
Ran 2 tests in 0.000s
OK

Only the directory marker changed; the test itself stayed the same.

This change lets discovery reach the existing file.
Python 3.14 changes the start-directory rule
Starting discovery at a namespace package is supported again in Python 3.14. The documentation separately says discovery does not search subdirectories without __init__.py. In the example above, tests is the start directory and unit is the child. The child rule is the one to check.

A start directory and its child follow different discovery rules.
For CI, check that the nested test appears in the verbose test log. Once the marker exists, set the discovery top-level directory to tests to see the full test name:
python -m unittest discover -s tests -t tests -v

Verbose output lets you check that the nested test ran.
The output should include unit.test_total.TotalTest.test_sum. If the nested test is essential, a one-test smoke run should not count as a complete run.

Check the count and the name of the test you expect to run.
References: Python 3.12 test discovery · Python 3.14 test discovery
AI disclosure: This guide and its diagrams were generated by an AI assistant. The output cards show output from real Python 3.12 runs; the text was arranged to fit the cards.
Top comments (0)