JUnit XML reporting helps share test results in a standard format. Continuous Integration (CI) tools use it to show test outcomes clearly.
JUnit XML reporting for CI in PyTest
pytest --junitxml=path/to/report.xml
This command runs pytest and saves results in JUnit XML format.
The file path can be any valid location where you want the report saved.
report.xml in the current folder.pytest --junitxml=report.xml
tests/ folder and saves the report in results/test-results.xml.pytest tests/ --junitxml=results/test-results.xml
pytest -v --junitxml=report.xml
This simple test file has two tests. Running pytest with --junitxml=report.xml creates a JUnit XML report file named report.xml.
The CI system can read this file to show test results.
def test_addition(): assert 1 + 1 == 2 def test_subtraction(): assert 5 - 3 == 2 # Run this in terminal: # pytest --junitxml=report.xml
Make sure the folder for the report file exists before running pytest.
CI tools like Jenkins, GitLab, and GitHub Actions can automatically read JUnit XML reports.
You can combine --junitxml with other pytest options like -v for more details.
JUnit XML reporting creates a standard test result file for CI tools.
Use pytest --junitxml=filename.xml to generate the report.
This helps teams see test results clearly and track test health over time.