Skip to content

pytest node IDs embed an absolute path #85

Description

@tony

Summary

Every collected doctest id embeds the absolute path of the file it came from, repeated after the path pytest already prints. That makes the id machine-specific, so --deselect, -k, --lf and JUnit XML all carry a path that only resolves on the machine that produced it.

Reproduction

$ pytest docs/quickstart.md --collect-only -q

Expected

docs/quickstart.md::quickstart.md[0]
docs/quickstart.md::quickstart.md[1]

The path pytest already prints, then the page and the block's index — machine-independent, and still one id per block.

pytest's own text-file collector produces quickstart.md::quickstart.md because it collects a whole file as a single test. doctest_docutils collects per block, so dropping the index would collapse a page's ids together, which is a separate change from removing the absolute path and is not what this issue asks for. See #88, acceptance criterion 3.

Actual

docs/quickstart.md::/home/you/proj/docs/quickstart.md[0]
docs/quickstart.md::/home/you/proj/docs/quickstart.md[1]
Versions

gp-libs v0.0.19, CPython 3.14, pytest 9.1.1.

Root cause

DocTestDocutilsFile.collect() hands the finder the full path as the test name:

for test in finder.find(
    text,
    str(self.path),
):

and the finder builds each name from it with test_name = f"{name}[{idx}]". The same argument serves two roles: it is also the DocTest.filename that failure reports point at, where an absolute path is correct.

DoctestTextfile.collect() keeps the two apart, passing self.path.name as the name and the path separately as the filename.

Why it matters

The id is the handle for --deselect, -k, --lf, JUnit XML and any CI annotation. An absolute path makes all of them machine-specific: a checked-in --deselect line that works on a laptop silently matches nothing in CI, and JUnit output leaks the developer's home directory into build artifacts.

It is also just long. The same path appears twice on every line of --collect-only.

Proposal

Use the base name for the test name and keep the absolute path as the DocTest.filename, so failure reports still resolve to the real file. This changes every consumer's ids, so it is a breaking change worth its own release note.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions