Test Overview
This test runs a simple pytest test case and generates a JUnit XML report. It verifies that the test passes and the XML report file is created for CI integration.
Jump into concepts and practice - no test required
This test runs a simple pytest test case and generates a JUnit XML report. It verifies that the test passes and the XML report file is created for CI integration.
import pytest import os import sys def test_addition(): assert 2 + 3 == 5 if __name__ == '__main__': # Run pytest with JUnit XML report output retcode = pytest.main(['-v', '--junitxml=report.xml']) # Check if report.xml file is created assert os.path.exists('report.xml') # Exit with pytest return code sys.exit(retcode)
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts by running pytest with the --junitxml option to generate XML report | Terminal shows pytest starting, test_addition discovered | — | PASS |
| 2 | Pytest runs test_addition function | Test executes assertion 2 + 3 == 5 | Assert 2 + 3 == 5 is true | PASS |
| 3 | Pytest finishes test run and writes report.xml file | report.xml file is created in current directory | Check that report.xml file exists | PASS |
| 4 | Test script asserts report.xml file presence | File system contains report.xml | os.path.exists('report.xml') returns True | PASS |
| 5 | Test script exits with pytest return code 0 indicating success | Process ends with exit code 0 | — | PASS |
results.xml?--junitxml=filename.--junitxml=results.xml, which is correct syntax.pytest tests/ --junitxml=report.xmltests/ folder and generates a JUnit XML report file named report.xml.--junitxml=report.xml is specified, the file will be created with test results in XML format.pytest --junitxml=results.xml but the file results.xml is empty. What is the most likely cause?--junitxml is correct, pytest supports it, and invalid paths usually cause errors, not silent empty files.ci-report.xml. Which command should you use?--failfast and limit failures with --maxfail=1.--junitxml=ci-report.xml saves the report file as required.--junitxml=ci-report.xml, --failfast, and --maxfail=1. Others have wrong or conflicting flags.