Update Pytest to Generate JUnit XML for Import into Testery
Step 1: Install the pytest-xdist Plugin
To generate JUnit XML reports for your Pytest tests, you'll need to install the pytest-xdist
plugin. This plugin extends Pytest's functionality and provides the JUnit XML report generation feature.
Open your project's terminal and run the following command to install the plugin:
pip install pytest-xdist
Step 2: Update Your Pytest Configuration
Now that you have the pytest-xdist
plugin installed, you need to update your Pytest configuration to use it.
Create a Pytest configuration file, if you don't already have one. The configuration file should be named
pytest.ini
orpyproject.toml
(for newer Pytest versions).Add the following configuration to enable the JUnit XML report generation:
For
pytest.ini
:[pytest] junit_family = xunit2 junit_suite_name = Your_Test_Suite_Name junit_logging = all junit_log_passing_tests = True junit_log_truncate = True
Replace
Your_Test_Suite_Name
with an appropriate name for your test suite.For
pyproject.toml
:[tool.pytest.ini_options] junit_family = 'xunit2' junit_suite_name = 'Your_Test_Suite_Name' junit_logging = 'all' junit_log_passing_tests = true junit_log_truncate = true
Again, replace
Your_Test_Suite_Name
as needed.
Step 3: Run Your Pytest Tests
With your Pytest configuration updated, you can now run your tests as usual. Pytest will automatically use the JUnit XML reporter to generate XML reports.
To run your tests, use the following command:
pytest
After running the tests, you should see JUnit XML files generated in your project directory.
Step 4: Upload Your Test Results to Testery
The final step is to upload the generated JUnit XML files to Testery for further analysis. You can use the Testery CLI to achieve this. Ensure you have the Testery CLI installed:
pip install testery
Once installed, you can use the following command to upload your test results to Testery:
testery upload-results \
--environment develop \
--project Your_Project_Name \
--file junit.xml
Replace Your_Project_Name
with your specific project name and adjust the --file
option to point to the location of your JUnit XML files generated by Pytest.
This step will make your Pytest test results accessible within Testery, allowing you to monitor and analyze them efficiently.
Last updated
Was this helpful?