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: Incorrect (?) file reported for inherited tests #9388
I'm not sure if this is correct or not. In CircleCI, it prevents the "split tests by timing" feature from working correctly because it cannot find e.g. example/test_something.py in the XML doc. Is this intended? Is there a better method for inheriting tests?
Not strictly related but I figure anyone with domain-specific knowledge can answer this too: functional tests have their classname set to the module containing them, not the function itself. This means that Circle cannot divide these tests any more granularly than by file, whereas class-based tests can be split by class (because the classname points to the class). Any idea why the discrepancy?
The nodeid is example/test_something.py::TestPlain::test_something, but file points to base.py. That happens because junitxml takes file and line from item.location, which is where the function is defined, not where it was collected.
I work on tooling that reads pytest's JUnit XML and maps test results back to files. For that, and for CircleCI-style splitting by timing, the collected module is what you want, since that's the file you pass on the command line.
On Windows the path also uses backslashes (example\base.py) even though the nodeid uses /, so the same test can show a different file depending on the OS.
Would you accept a PR that makes junitxml take file from the nodeid's path part (so it's the collected module and always uses /)? The open question is line: it's the line in base.py, so it would no longer match file. I can see three options: drop line when the function is defined in another file, keep it as is, or leave file alone and only normalise the separator. Happy to go with whichever you prefer.
Activity
tpict commentedon Dec 9, 2021
Not strictly related but I figure anyone with domain-specific knowledge can answer this too: functional tests have their
classnameset to the module containing them, not the function itself. This means that Circle cannot divide these tests any more granularly than by file, whereas class-based tests can be split by class (because theclassnamepoints to the class). Any idea why the discrepancy?surkuar commentedon Nov 25, 2026
This still happens on pytest 9.2.0, and not only with
unittest.TestCase. A plain pytest class that inherits its tests behaves the same way:The nodeid is
example/test_something.py::TestPlain::test_something, butfilepoints tobase.py. That happens because junitxml takesfileandlinefromitem.location, which is where the function is defined, not where it was collected.I work on tooling that reads pytest's JUnit XML and maps test results back to files. For that, and for CircleCI-style splitting by timing, the collected module is what you want, since that's the file you pass on the command line.
On Windows the path also uses backslashes (
example\base.py) even though the nodeid uses/, so the same test can show a differentfiledepending on the OS.Would you accept a PR that makes junitxml take
filefrom the nodeid's path part (so it's the collected module and always uses/)? The open question isline: it's the line inbase.py, so it would no longer matchfile. I can see three options: droplinewhen the function is defined in another file, keep it as is, or leavefilealone and only normalise the separator. Happy to go with whichever you prefer.