You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
junitxml: file attribute uses backslashes on Windows (xunit1/legacy) #15453
With junit_family=xunit1 (or legacy), the file attribute of <testcase> uses the OS path separator. On Windows it contains backslashes, while the nodeid for the same test uses /:
On Linux/macOS the same run gives file="tests/sub/test_plain.py". So one test suite produces different file values depending on the OS that ran it. Tools that read this attribute (CI test-splitting by timing, test-result dashboards, or anything matching results back to files in the repo) have to normalise it themselves or the paths won't match across runners.
I ran into this while working on tooling that reads pytest JUnit XML from CI runs on several OSes. I noticed it while looking into #9388, which is about the same attribute but a different problem.
Cause
_NodeReporter.record_testreport in src/_pytest/junitxml.py sets "file": location[0]. That value comes from Item.location, which builds the path with bestrelpath, so it uses os.sep. That's fine for terminal output, but the XML is a file that gets passed between systems.
Expected
file uses / on every platform, the same as the nodeid. Using nodes.SEP in junitxml only, without changing Item.location, would keep terminal output on Windows as it is.
I'd be happy to send a PR with a test if that sounds right.
Activity
junitxml: use forward slashes in the testcase file attribute