Test Overview
This test runs a simple function and publishes the test result using pytest's reporting. It verifies that the function returns the expected output and that the test result is correctly reported as pass.
Jump into concepts and practice - no test required
This test runs a simple function and publishes the test result using pytest's reporting. It verifies that the function returns the expected output and that the test result is correctly reported as pass.
import pytest def add(a, b): return a + b def test_add(): result = add(2, 3) assert result == 5
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | pytest test runner initializes and loads test_add function | — | PASS |
| 2 | Calls add(2, 3) | Function add executes and returns 5 | — | PASS |
| 3 | Assert result == 5 | Test checks if returned value is 5 | assert result == 5 | PASS |
| 4 | Test result published by pytest | pytest records test as PASSED in test report | Test outcome is PASS | PASS |
results.xml?--junitxml to save results in XML format.pytest --junitxml=results.xml saves the test report as results.xml.pytest --junitxml=report.xml
--junitxml=report.xml tells pytest to save results in XML format to the file report.xml.pytest --junitxml report.xml but no report.xml file is created. What is the likely problem?--junitxml=report.xml.report.xml as a positional argument, so no file is created.--junitxml=report.xml correctly saves results in XML format.--durations=0 tells pytest to show durations for all tests.pytest --junitxml=report.xml --durations=0 is valid and achieves the goal.