Package: pytest-azurepipelines
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 commandDisplays the number of failed tests if there were failures as an error message in the UIAutomatically formats code coverage and uploads coverage data if pytest-cov is installedSupports running inside a Docker container and automatically uploads test resultsInstallationYou can install “pytest-azurepipelines” viapipfromPyPI:$ pip install pytest-azurepipelinesUsageThis plugin requires no configuration.Here is an example of installing the plugin and running the tests.-script:|python -m pip install --upgrade pippip install pytest pytest-azurepipelinespip install -e .displayName:'Installdependencies'-script:|python -m pytest tests/displayName:'pytest'If you want to change the Azure Pipelines “Test Run Title”, you can provide the–test-run-titleflag with the run title.-script:|pip install pytest pytest-azurepipelinespytest 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-docstringsflag:-script:|pip install pytest pytest-azurepipelinespytest tests/ --test-run-title="Windows Test" --napoleon-docstringsThe directory where the html reports are searched for can be changed with the–report-dirflag. It defaults tohtmlcov:-script:|pip install pytest pytest-azurepipelinespytest tests/ --report-dir=custom_folderFixturesThe following fixtures are made available by this plugin.record_pipelines_propertyCallingrecord_pipelines_property(key: str, value: str)will result inPropertytags being added to thetest-casefor the related node.deftest_basic(record_pipelines_property):record_pipelines_property("test","value")assert1==1add_pipelines_attachmentAdd an attachment to a node test-case by calling theadd_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.deftest_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")assert1==1Using the automatic code coverage uploadFrom 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–covflag with (optional, but required) path to your code files and also ensure you add–cov-report htmlas an option.-script:|pip install pytest pytest-azurepipelines pytest-covpytest tests/ --cov my_project --cov-report htmlTo disable coverage upload, use the–no-coverage-uploadflag.Running in DockerThe 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.dockerrun--user"$(id-u):$(id-g)"...To disable docker discovery, use the–no-docker-discoveryflag.ContributingContributions are very welcome.LicenseDistributed under the terms of the MIT license, “pytest-azurepipelines” is free and open source softwareIssuesIf you encounter any problems, pleasefile an issuealong with a detailed description.