pytest-azurepipelines
pytest-azurepipelines is a plugin for the pytest testing framework that enhances its integration with Azure Pipelines. It formats pytest output to improve readability in the Azure Pipelines UI, automatically uploads test results, and integrates with pytest-cov for code coverage reporting. The current version is 1.0.5. Releases appear to be event-driven rather than on a fixed cadence, with significant updates in 2020 and 2022-2023.
Warnings
- breaking Version 1.0.0rc3 dropped support for older Pytest releases (pre-5.0.0) and Python 2. Using `pytest-azurepipelines` with these older versions will lead to failures.
- gotcha `pytest-azurepipelines` versions prior to 1.0.4 had known compatibility issues when used with `pytest-xdist` for parallel test execution. This could lead to incomplete or incorrectly reported results.
- gotcha While `pytest-azurepipelines` supports automatic code coverage upload, it requires `pytest-cov` to be installed and `--cov-report html` to be explicitly added to your `pytest` command line. Without `--cov-report html`, the HTML coverage report will not be packaged as an artifact.
- gotcha Each `script` block in an Azure Pipelines YAML typically runs in a new shell. If you are using Python virtual environments, you must activate the virtual environment in *each* `script` step that needs to execute Python commands to ensure correct dependency resolution.
- gotcha Under certain complex test setups or specific `pytest` command line arguments, the plugin might issue warnings about failing to find or publish `test-output.xml` because it attempts to process results before the file is fully written.
Install
-
pip install pytest-azurepipelines
Imports
- record_pipelines_property
def test_example(record_pipelines_property): record_pipelines_property('key', 'value') - add_pipelines_attachment
import os def test_attachment_example(add_pipelines_attachment): # Create a dummy file for attachment file_path = 'temp_attachment.txt' with open(file_path, 'w') as f: f.write('This is an attachment.') add_pipelines_attachment(file_path, 'Temporary Test Data') os.remove(file_path)
Quickstart
# Example Azure Pipelines YAML snippet
steps:
- script: |
python -m pip install --upgrade pip
pip install pytest pytest-azurepipelines
pip install -e . # Install your project's test dependencies
pytest tests/
displayName: 'Run Pytest with Azure Pipelines Plugin'