![]() |
VOOZH | about |
The testing framework in Python which is used to write and execute test codes is called Pytest. There occur some circumstances in Pytest when we need to store the test execution results in an XML file apart from just displaying them in the terminal. In this article, we will discuss how to store the test execution results of Pytest in an XML file.
Syntax: pytest python_file.py -v --junitxml="xml_file.xml"
Here,
- python_file: It is the name of the Python test file which you want to execute tests.
- xml_file: It is the name of the XML file in which you want to store test execution results.
In this example, we have created a Python file, gfg2.py, which has four test cases, checking floor, equality, subtraction, and square root. We will store the test execution results in gfg.xml file.
Output
Now, we will run the following command in terminal:
pytest gfg2.py -v --junitxml="gfg.xml"
Video:
In this another example, we have created a Python file, gfg3.py defined a string, then we have created 3 unit test cases on it, for removing substrings G, e and o. We will store the test execution results in gfg1.xml file.
Output
Now, we will run the following command in terminal:
pytest gfg3.py -v --junitxml="gfg1.xml"
Video: