0
0
PyTesttesting~20 mins

JUnit XML reporting for CI in PyTest - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JUnit XML Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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
ANo file is created; the option only prints XML to the console.
BA JSON file named <code>report.xml</code> is created with test results.
CA file named <code>report.xml</code> containing test results in JUnit XML format is created.
DA binary file named <code>report.xml</code> is created containing test logs.
Attempts:
2 left
💡 Hint
JUnit XML is a standard XML format for test reports used by CI tools.
assertion
intermediate
2: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()
Aassert root.find('testcase[@name="test_example"]') is None
Bassert any(tc.attrib.get('name') == 'test_example' for tc in root.iter('testcase'))
Cassert root.find('testcase').attrib['name'] == 'test_example'
Dassert 'test_example' in root.text
Attempts:
2 left
💡 Hint
JUnit XML test cases are under elements with a 'name' attribute.
🔧 Debug
advanced
2: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?
AThe file was created but deleted by pytest after the run.
BThe <code>--junitxml</code> option is deprecated and ignored by pytest.
CThe test suite had no tests, so no report was generated.
DThe pytest command ran in a different directory than expected, so the file was created elsewhere.
Attempts:
2 left
💡 Hint
Check the working directory of the pytest command in the CI job.
framework
advanced
2: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?
AAdd <code>addopts = --junitxml=junit-report.xml</code> under the [pytest] section in <code>pytest.ini</code>.
BSet an environment variable <code>PYTEST_JUNITXML=junit-report.xml</code>.
CCreate a <code>junit.xml</code> file manually before running pytest.
DAdd <code>junitxml = junit-report.xml</code> under the [pytest] section in <code>pytest.ini</code>.
Attempts:
2 left
💡 Hint
pytest.ini can add default command line options.
🧠 Conceptual
expert
2:00remaining
Interpreting JUnit XML test suite attributes
In a JUnit XML report generated by pytest, what does the testsuite attribute failures represent?
AThe number of test cases that failed due to assertion failures.
BThe number of test cases skipped or marked as expected failures.
CThe total number of tests executed including passed, failed, and skipped.
DThe number of tests that passed successfully.
Attempts:
2 left
💡 Hint
Failures count tests that failed assertions.