Test Overview
This test runs a simple PyTest test case inside Jenkins. It verifies that Jenkins can execute the PyTest command and that the test passes successfully.
Jump into concepts and practice - no test required
This test runs a simple PyTest test case inside Jenkins. It verifies that Jenkins can execute the PyTest command and that the test passes successfully.
import pytest def test_addition(): assert 2 + 3 == 5 if __name__ == '__main__': pytest.main(['-v'])
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Jenkins job starts and runs the shell command 'pytest -v' | Jenkins agent environment is ready with Python and PyTest installed | — | PASS |
| 2 | PyTest discovers the test_addition function | PyTest test runner lists test_addition as a test to run | — | PASS |
| 3 | PyTest executes test_addition | Test function runs and performs assertion 2 + 3 == 5 | Assert that 2 + 3 equals 5 | PASS |
| 4 | PyTest reports test_addition PASSED | Test report shows 1 passed test | Verify test result is PASS | PASS |
| 5 | Jenkins captures PyTest output and marks build as SUCCESS | Jenkins console log shows PyTest output with PASS status | Jenkins build status is SUCCESS | PASS |
pytest in Jenkins?--junitxml=filename.sh to run shell commands, so sh 'pytest --junitxml=results.xml' is correct.pipeline {
agent any
stages {
stage('Test') {
steps {
sh 'pytest --junitxml=results.xml'
junit 'results.xml'
}
}
}
}sh stepsh command runs pytest and generates results.xml with test results.junit stepjunit step reads results.xml and shows test results in Jenkins UI.sh 'pytest --junitxml=results.xml' junit 'results.xml'
FileNotFoundError: results.xml not found. What is the likely cause?results.xml.junit step needs the XML file; if missing, it errors out.pytest with paths of changed files, then use junit to show results.junit -> Option C