Skip to main content

Formatting PyTest output for Azure Pipelines UI

Project description

Build status PyPI version Python versions PyPI download month

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!


Features:

  • Formats the PyTest output to show test docstrings and module names instead of just test case names in the Azure Pipelines UI.

  • Uploads test results automatically, no need for a separate 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

Use this plugin with the [vs-pytest](https://marketplace.visualstudio.com/items?itemName=AnthonyShaw.vss-pytest) extension installed to see granular pytest data inside the Azure UI:

https://github.com/tonybaloney/pytest-azurepipelines/raw/master/screenshot.png

Installation

You can install “pytest-azurepipelines” via pip from PyPI:

$ pip install pytest-azurepipelines

Usage

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"

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" --napoleon-docstrings

Fixtures

The following fixtures are made available by this plugin.

record_pipelines_property

Calling record_pipelines_property(key: str, value: str) will result in Property tags being added to the test-case for the related node.

def test_basic(record_pipelines_property):
    record_pipelines_property("test", "value")
    assert 1 == 1

add_pipelines_attachment

Add an attachment to a node test-case by calling the add_pipelines_attachment(path: str, description: str) function with the filepath and a description.

Attachments can be viewed in the Azure Pipelines UI under the ‘Attachments’ tab for a test case.

def test_attachment(add_pipelines_attachment):
    pth = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'fixture.gif')
    add_pipelines_attachment(path, "peanut butter jelly time")
    assert 1 == 1

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.

Contributing

Contributions are very welcome.

License

Distributed under the terms of the MIT license, “pytest-azurepipelines” is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-azurepipelines-1.0.0a2.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

pytest_azurepipelines-1.0.0a2-py2-none-any.whl (6.5 kB view details)

Uploaded Python 2

File details

Details for the file pytest-azurepipelines-1.0.0a2.tar.gz.

File metadata

  • Download URL: pytest-azurepipelines-1.0.0a2.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.15

File hashes

Hashes for pytest-azurepipelines-1.0.0a2.tar.gz
Algorithm Hash digest
SHA256 7910f3db8e2e4516690e602c6c88a0abc0fbb93080d93f6fd2f5cbe9d5c24cad
MD5 31f82b38fcc43b395f726cf56f369af5
BLAKE2b-256 44a5ea68cf8b1231c3c94cff9af67ae5ec963fd24abfef0575585829317b6ca4

See more details on using hashes here.

File details

Details for the file pytest_azurepipelines-1.0.0a2-py2-none-any.whl.

File metadata

  • Download URL: pytest_azurepipelines-1.0.0a2-py2-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/2.7.15

File hashes

Hashes for pytest_azurepipelines-1.0.0a2-py2-none-any.whl
Algorithm Hash digest
SHA256 0c23dd345c38e1b33451e99cfb68c6da25b0d50392e8f3e81aed84db31296402
MD5 d69e58eeebb572b8597765adc0608984
BLAKE2b-256 8fdc266bf5c66a5054a85c7ad3ed82c6890055745810b5c89ff73deadecaf3a4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page