Formatting PyTest output for Azure Pipelines UI
Making Pytest easier to use with Microsoft Azure Pipelines.
Just run pytest with this plugin and see your test results in the Azure Pipelines UI!
- Formats the PyTest output to show test docstrings and module names instead of just test case names in the Azure Pipelines UI.
- Overloads the –junit-xml flag on execution with a default value
- Uploads test results automatically, no need for a seperate test results upload command
- Displays the number of failed tests if there were failures as an error message in the UI
- Automatically formats code coverage and uploads coverage data if pytest-cov is installed
- Supports running inside a Docker container and automatically uploads test results
$ pip install pytest-azurepipelines
This plugin requires no configuration.
Here is an example of installing the plugin and running the tests.
- script: | python -m pip install --upgrade pip pip install pytest pytest-azurepipelines pip install -e . displayName: 'Install dependencies' - script: | python -m pytest tests/ displayName: 'pytest'
If you want to change the Azure Pipelines “Test Run Title”, you can provide the –test-run-title flag with the run title.
- script: | pip install pytest pytest-azurepipelines pytest tests/ --test-run-title="Windows Test with junitxml" displayName: 'pytest with junitxml flag'
If you have long docstrings in your functions and want them to be shortened, you can use the –napoleon-docstrings flag:
- script: | pip install pytest pytest-azurepipelines pytest tests/ --test-run-title="Windows Test with junitxml" --napoleon-docstrings
Using the automatic code coverage upload
From version 0.6.0, pytest will upload successful coverage data into a format that Azure supports and package the htmlcov directory into a ZIP file as an artifact for the build.
To use this feature, add the –cov flag with (optional, but required) path to your code files and also ensure you add –cov-report html as an option.
- script: | pip install pytest pytest-azurepipelines pytest-cov pytest tests/ --cov my_project --cov-report html
To disable coverage upload, use the –no-coverage-upload flag.
Running in Docker
The plugin automatically detects when running inside a docker container. It will apply the mappings to the path to report them back to Azure Pipelines using the path from the host that has been bind mounted to the docker container.
No configuration is required if bind mounting is used to the path the pytest output is written to. Also ensure the files are written using an account the host has access to, this can be done by supplying the user and group of the host account to the run command.
docker run --user "$(id -u):$(id -g)" ...
To disable docker discovery, use the –no-docker-discovery flag.
Contributions are very welcome.
Distributed under the terms of the MIT license, “pytest-azurepipelines” is free and open source software
If you encounter any problems, please file an issue along with a detailed description.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size pytest_azurepipelines42-0.8.3-py2-none-any.whl (6.4 kB)||File type Wheel||Python version py2||Upload date||Hashes View hashes|
|Filename, size pytest_azurepipelines42-0.8.3-py3-none-any.whl (6.4 kB)||File type Wheel||Python version py3||Upload date||Hashes View hashes|
|Filename, size pytest-azurepipelines42-0.8.3.tar.gz (6.2 kB)||File type Source||Python version None||Upload date||Hashes View hashes|
Hashes for pytest_azurepipelines42-0.8.3-py2-none-any.whl
Hashes for pytest_azurepipelines42-0.8.3-py3-none-any.whl
Hashes for pytest-azurepipelines42-0.8.3.tar.gz