Skip to content

pytest docs/examples --collect-only collects 0 tests after conftest.py refactor #794

@planetf1

Description

@planetf1

Summary

Directory-level collection of docs/examples/ is broken — uv run pytest docs/examples/ --collect-only returns 0 items. Specifying individual files still works fine.

Cause

Introduced in d3d6040 (#742). The pytest_collect_file hook in docs/examples/conftest.py was changed to return None for non-skipped files, with the intention that pytest_pycollect_makemodule would handle collection instead.

However, pytest_pycollect_makemodule only fires for files matching the python_files pattern (test_*.py / *_test.py). Example files (e.g. hello_world.py) don't match, so during directory traversal they're silently dropped.

Fix

Restore an explicit collector return in pytest_collect_file for runnable examples. One-liner — return ExampleModule.from_parent(parent, path=file_path) instead of None at line 421.

Reproduction

uv run pytest docs/examples/ --collect-only
# collected 0 items

uv run pytest docs/examples/hello_world.py --collect-only
# collected 1 item  ✓

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingtesting

Type

No fields configured for Bug.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions