Skip to content

Try using pytest 9+ subtests for tests_docs.py #2608

@simonw

Description

@simonw

New feature in pytest 9: https://docs.pytest.org/en/stable/changelog.html#pytest-9-0-0-2025-11-05

subtests are an alternative to parametrization, useful in situations where the parametrization values are not all known at collection time.

Example:

def  contains_docstring(p: Path) -> bool:
  """Return True if the given Python file contains a top-level docstring."""
    ...

def  test_py_files_contain_docstring(subtests: pytest.Subtests) -> None:
    for path in Path.cwd().glob("*.py"):
        with subtests.test(path=str(path)):
            assert contains_docstring(path)

Would be interesting to try these in test_docs.py.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions