On , I learnt ...
How to use xmllint
to extract the failing test filenames from a JUnit-XML file
Pytest will generate a JUnit-XML result report when run with the
--junitxml
option.
To extract the names the files containing failing tests, this
xmllint
command can be used:
xmllint --xpath '//testcase[.//failure]/@file' results.xml | \
tr " " "\n" | awk 'BEGIN { FS="\"" } { print $2 }' | \
sort | uniq
Here we:
-
Use an XPath filter to select all
file
attributes from<testcase>
elements containing a<failure>
child element. -
Use
tr
andawk
to convert the output into a list of filenames. -
Use
sort
anduniq
to print a list of unique filenames.
This is a little convoluted. XMLLint doesn’t support using a string
XPath
function to print the attribute values of all matches (it only prints the first
one) which is why we need to pipe out to standard Unix tools.