Skip to main content

A pytest plugin for generating NUnit3 test result XML output

Project description

Build status PyPI version Python versions PyPI download month

A pytest plugin for generating NUnit3 test result XML output

This plugin is in beta.

Command-line options

--nunit-xml

A string value to set the file name of the generated XML file.

Argument takes a path to the output file, either relative, or absolute.

--nunit-prefix

A string value to prefix all test case names the string provided.

Defaults to an empty string.

INI Options

nunit_show_username

Boolean value to include the system username in the test run properties.

Defaults to false

nunit_show_user_domain

Boolean value to include the system user domain in the test run properties.

Defaults to false

nunit_suite_name

String value to set the test suite name.

Defaults to 'pytest'

nunit_attach_on

Enumeration to control whether the attachments property is set on all test cases when the add_nunit_attachment is used.

Can be one of:

  • any - Include test attachments for all outcomes (Default)

  • pass - Include test attachments for only passed test cases

  • fail - Include test attachments for only failed test cases

Fixtures

The following fixtures are made available by this plugin.

record_nunit_property

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

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

add_nunit_attachment

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

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

Usage with Azure Pipelines

Add the following steps to your build job to publish the results to Azure Pipelines:

- script: "pip install pytest-nunit"

- script: |
    python -m pytest tests -v --nunit-xml=test-results.xml
  continueOnError: true

- task: PublishTestResults@2
  inputs:
    testResultsFormat: NUnit
    testResultsFiles: '**/test-results.xml'

Skipped Tests

Skipped tests will have the reason attribute (if provided) included in the results.

https://github.com/pytest-dev/pytest-nunit/raw/master/docs/source/_static/screen_skips.png

Attachments

Using the add_nunit_attachment fixture will render any attachments in the “attachments” tab inside the Tests console:

https://github.com/pytest-dev/pytest-nunit/raw/master/docs/source/_static/screen_attachments.png

Failures and xfails

Any failed tests, whether as xpass or xfail, will have the error output and comparison, as well as the failing line in the stack trace.

https://github.com/pytest-dev/pytest-nunit/raw/master/docs/source/_static/screen_fails.png

Compatibility with other plugins

x-dist

When running with -f, make sure to add in your pytest config file (setup.cfg etc) looponfailroots = testdir to exclude xml report files from being watched for changes.

Check looponfails

History

0.4.0 (28th August 2019)

  • Added user domain (contribution by @williano)

  • Added tests and help for xdist execution (contribution by @mei-li)

  • Dynamically use the keyword list when generating schema to avoid reserved word collision (contribution by @gerhardtdatsomor)

  • Add method names, classnames and module names to output (contribution by @adekanyetomie)

  • Added locale and uiculture properties to runtime output (contribution by @terrameijar)

  • Added nunit_attach_on INI option to control when attachments are included in test cases.

0.3.0 (15th July 2019)

  • Added --nunit-prefix option.

0.2.1 (15th July 2019)

  • First stable release

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-nunit-0.4.0.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

pytest_nunit-0.4.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest-nunit-0.4.0.tar.gz.

File metadata

  • Download URL: pytest-nunit-0.4.0.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for pytest-nunit-0.4.0.tar.gz
Algorithm Hash digest
SHA256 af7f38e59e2eb6aae84ecf65fe3012eb08a49b2e93f71c34e3a4b2c9ad93785f
MD5 36cccf04b50e50064a5499954ca7e682
BLAKE2b-256 342b8b5d985d2f12df2df3962f9a1be9a9408ffe855f435ef8bd141123d99e1c

See more details on using hashes here.

File details

Details for the file pytest_nunit-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_nunit-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for pytest_nunit-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 012d5370040eba24e4ce5d9a52581f766a65b0967d56bdc2ce8f23002619999e
MD5 fdf57e46b3db5ef8cc8f3f38d6906ef8
BLAKE2b-256 0fbc7414df30cb9708486b49960558e8494663558e75269067218e655b67021c

See more details on using hashes here.

Supported by

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