{"id":4720,"library":"pytest-azurepipelines","title":"pytest-azurepipelines","description":"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.","status":"active","version":"1.0.5","language":"en","source_language":"en","source_url":"https://github.com/Azure/pytest-azurepipelines","tags":["pytest","azure-pipelines","ci-cd","testing","coverage"],"install":[{"cmd":"pip install pytest-azurepipelines","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Core testing framework this plugin extends.","package":"pytest","optional":false},{"reason":"Required for automatic code coverage upload and reporting features.","package":"pytest-cov","optional":true}],"imports":[{"note":"Used as a pytest fixture to add custom properties to test cases in the Azure Pipelines UI. No explicit import statement is typically needed in conftest.py or test files, as pytest discovers fixtures.","symbol":"record_pipelines_property","correct":"def test_example(record_pipelines_property):\n    record_pipelines_property('key', 'value')"},{"note":"Used as a pytest fixture to add attachments to test cases in the Azure Pipelines UI. Similar to record_pipelines_property, it's discovered by pytest.","symbol":"add_pipelines_attachment","correct":"import os\n\ndef test_attachment_example(add_pipelines_attachment):\n    # Create a dummy file for attachment\n    file_path = 'temp_attachment.txt'\n    with open(file_path, 'w') as f:\n        f.write('This is an attachment.')\n    add_pipelines_attachment(file_path, 'Temporary Test Data')\n    os.remove(file_path)"}],"quickstart":{"code":"# Example Azure Pipelines YAML snippet\nsteps:\n- script: |\n    python -m pip install --upgrade pip\n    pip install pytest pytest-azurepipelines\n    pip install -e . # Install your project's test dependencies\n    pytest tests/\n  displayName: 'Run Pytest with Azure Pipelines Plugin'","lang":"bash","description":"Install `pytest-azurepipelines` alongside `pytest` in your Azure Pipeline environment. The plugin automatically integrates with Azure Pipelines by running `pytest` in a script step, formatting output and uploading test results without further configuration."},"warnings":[{"fix":"Upgrade `pytest` to version 5.0.0 or higher and ensure your project uses Python 3.","message":"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.","severity":"breaking","affected_versions":"<1.0.0rc3"},{"fix":"Upgrade to `pytest-azurepipelines` 1.0.4 or higher to ensure proper `pytest-xdist` support. Also, ensure `pytest-xdist` itself is up-to-date.","message":"`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.","severity":"gotcha","affected_versions":"<1.0.4"},{"fix":"Install `pytest-cov` (e.g., `pip install pytest-cov`) and modify your `pytest` command to include `--cov your_project_module --cov-report html`.","message":"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.","severity":"gotcha","affected_versions":">=0.6.0"},{"fix":"Prepend `source .venv/bin/activate` (for Linux/macOS agents) or `.venv\\Scripts\\activate` (for Windows agents) to each `script` block that runs Python commands after virtual environment creation.","message":"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.","severity":"gotcha","affected_versions":"All versions when used in Azure Pipelines"},{"fix":"While the plugin generally handles this, if warnings persist, simplify `junitxml` paths or ensure the `pytest` command completes successfully before any subsequent custom test result processing steps. In some cases, updating `pytest` itself can resolve underlying timing issues.","message":"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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}