pytest-nunit

1.0.7 · active · verified Mon Apr 13

pytest-nunit is a pytest plugin for generating NUnit3 test result XML output. It integrates seamlessly with `pytest` to produce reports compatible with NUnit test runners. The project is actively maintained with frequent updates, including recent support for `pytest` 8 and ongoing compatibility improvements.

Warnings

Install

Quickstart

To use `pytest-nunit`, simply install the package. It integrates automatically with `pytest`. You can then generate an NUnit XML report by running `pytest` with the `--nunit-xml` option, specifying the desired output file path. This example demonstrates running tests and generating an XML report named `test-results.xml`.

import pytest

# Create a dummy test file, e.g., test_example.py
with open('test_example.py', 'w') as f:
    f.write('def test_success():\n    assert True\n\ndef test_failure():\n    assert False\n')

# Run pytest with nunitxml output
# This will generate a 'test-results.xml' file in the current directory
pytest.main(['test_example.py', '--nunit-xml=test-results.xml'])

# Clean up (optional)
import os
os.remove('test_example.py')
os.remove('test-results.xml')

view raw JSON →