Pytest Tutorial
Selected Reading
- Pytest - Discussion
- Pytest - Useful Resources
- Pytest - Quick Guide
- Pytest - Conclusion
- Pytest - Summary
- Test Execution Results in XML
- Pytest - Run Tests in Parallel
- Stop Test Suite after N Test Failures
- Pytest - Xfail/Skip Tests
- Pytest - Parameterizing Tests
- Pytest - Conftest.py
- Pytest - Fixtures
- Pytest - Grouping the Tests
- Substring Matching of Test Names
- Execute a Subset of Test Suite
- Pytest - File Execution
- Pytest - Starting With Basic Test
- Identifying Test files and Functions
- Pytest - Environment Setup
- Pytest - Introduction
- Pytest - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Test Execution Results in XML
Test Execution Results in XML Format
We can generate the details of the test execution in an xml file. This xml file is mainly useful in cases where we have a dashboard that projects the test results. In such cases, the xml can be parsed to get the details of the execution.
We will now execute the tests from test_multiplcation.py and generate the xml by running
pytest test_multippcation.py -v --junitxml="result.xml"
Now we can see result.xml is generated with the following data −
<?xml version = "1.0" encoding = "utf-8"?> <testsuite errors = "0" failures = "1" name = "pytest" skips = "0" tests = "4" time = "0.061"> <testcase classname = "test_multippcation" file = "test_multippcation.py" pne = "2" name = "test_multippcation_11[1-11]" time = "0.00117516517639> </testcase> <testcase classname = "test_multippcation" file = "test_multippcation.py" pne = "2" name = "test_multippcation_11[2-22]" time = "0.00155973434448"> </testcase> <testcase classname = "test_multippcation" file = "test_multippcation.py" pne = "2" name = "test_multippcation_11[3-35]" time = "0.00144290924072"> failure message = "assert (11 * 3) == 35">num = 3, output = 35 @pytest.mark.parametrize("num, output",[(1,11),(2,22),(3,35),(4,44)]) def test_multippcation_11(num, output):> assert 11*num == output E assert (11 * 3) == 35 test_multippcation.py:5: AssertionErro </failure> </testcase> <testcase classname = "test_multippcation" file = "test_multippcation.py" pne = "2" name = "test_multippcation_11[4-44]" time = "0.000945091247559"> </testcase> </testsuite>
Here, the tag <testsuit> summarises there were 4 tests and the number of failures are 1.
The tag <testcase> gives the details of each executed test.
<failure> tag gives the details of the failed test code.