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.
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 |