Challenge - 5 Problems
JUnit XML Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
JUnit XML report generation with pytest
What is the output file generated by pytest when using the option
--junitxml=report.xml?PyTest
pytest --junitxml=report.xml
Attempts:
2 left
💡 Hint
JUnit XML is a standard XML format for test reports used by CI tools.
✗ Incorrect
The
--junitxml=filename option tells pytest to write test results in JUnit XML format to the specified file. This file is XML, not JSON or binary.❓ assertion
intermediate2:00remaining
Validating JUnit XML report content
Which assertion correctly checks that the JUnit XML report contains a test case with the name
test_example?PyTest
import xml.etree.ElementTree as ET with open('report.xml') as f: tree = ET.parse(f) root = tree.getroot()
Attempts:
2 left
💡 Hint
JUnit XML test cases are under elements with a 'name' attribute.
✗ Incorrect
Option B correctly iterates over all elements and checks if any has the name 'test_example'. Option B checks for None which is opposite. Option B only checks the first testcase. Option B checks text content which is unreliable.
🔧 Debug
advanced2:00remaining
Fixing missing JUnit XML report in CI pipeline
A CI pipeline runs pytest with
--junitxml=results.xml but the results.xml file is missing after the run. What is the most likely cause?Attempts:
2 left
💡 Hint
Check the working directory of the pytest command in the CI job.
✗ Incorrect
Pytest creates the JUnit XML file in the current working directory. If the CI job runs pytest in a different directory than expected, the file will be created there, not in the expected location. The option is not deprecated. Pytest creates the file even if no tests run. Pytest does not delete the file after creation.
❓ framework
advanced2:00remaining
Configuring pytest to always generate JUnit XML reports
How can you configure pytest to always generate a JUnit XML report named
junit-report.xml without specifying --junitxml on the command line?Attempts:
2 left
💡 Hint
pytest.ini can add default command line options.
✗ Incorrect
The
addopts setting in pytest.ini allows adding default command line options like --junitxml=filename. There is no junitxml config option. Creating a file manually or environment variable does not trigger report generation.🧠 Conceptual
expert2:00remaining
Interpreting JUnit XML test suite attributes
In a JUnit XML report generated by pytest, what does the
testsuite attribute failures represent?Attempts:
2 left
💡 Hint
Failures count tests that failed assertions.
✗ Incorrect
The
failures attribute counts tests that failed due to assertion failures. Skipped tests are counted separately. Total tests is in tests attribute. Passed tests are total minus failures, errors, and skipped.