Skip to content

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

Closed

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  ✓

Activity

  1. added this to the Release 0.5.0 milestone on Apr 8, 2026
  2. self-assigned this
    on Apr 8, 2026
  3. added theissue type on Apr 8, 2026
  4. added
    bug
    on Apr 8, 2026
  5. planetf1 commented on Apr 8, 2026

    @planetf1
    ContributorAuthor

    Hopefully will fix your issue @jakelorocco : thanks for spotting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugtesting

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions