Registry / testing / pytest-nunit

pytest-nunit

JSON →
library1.0.7pypypiunverified

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.

pip install pytest-nunit
INSTALL
IMPORT
SIG · PYTEST-NUNIT
P
pytest-nunit
testingpythonv1.0.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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')
Debug
Known issues
breakingOlder versions of `pytest-nunit` (prior to 1.0.7) may not be fully compatible with `pytest` 8.0.0 and newer due to significant internal breaking changes introduced in `pytest`'s collection phase.
fix
Upgrade to `pytest-nunit` version 1.0.7 or later to ensure compatibility with `pytest` 8.x series.
affects: <1.0.7
deprecatedThe `datetime.utcnow()` function, used internally by `pytest-nunit`, was replaced in version 1.0.6 due to deprecation in Python. Running older `pytest-nunit` versions on newer Python environments might surface deprecation warnings related to `datetime` usage.
fix
Update `pytest-nunit` to version 1.0.6 or newer to use `datetime.now(timezone.utc)` and avoid `utcnow()` deprecation warnings.
affects: <1.0.6
gotchaThe `xmlschema` package became a required dependency starting from `pytest-nunit` version 1.0.2. Environments that do not automatically resolve transitive dependencies might fail if `xmlschema` is not explicitly installed.
fix
Ensure `xmlschema` is installed alongside `pytest-nunit`. Typically `pip install pytest-nunit` handles this, but manual installation (`pip install xmlschema`) might be needed in isolated environments.
affects: All versions >=1.0.2
gotchaThe primary method to generate an NUnit XML report is by using the `--nunit-xml=<path>` command-line option. Forgetting this option will result in `pytest` running tests but not producing the desired XML output.
fix
Always include `--nunit-xml=your_report_file.xml` when invoking `pytest` to ensure the report is generated.
affects: All versions
deprecatedThe `nunit_suite_name` INI option is deprecated and its value is ignored by `pytest-nunit`.
fix
Avoid using the `nunit_suite_name` INI option as it has no effect.
affects: All versions
gotchaWhen using `pytest-xdist` with the `-f` (looponfail) option, it's recommended to add `looponfailroots = testdir` to your `pytest.ini` or `setup.cfg`. This prevents the generated XML report files from being continuously watched for changes, which can lead to unexpected behavior or performance issues.
fix
Add `looponfailroots = testdir` to your `pytest` configuration file (e.g., `pytest.ini`) to exclude XML report files from being watched by `pytest-xdist`'s looponfail feature.
affects: All versions when used with pytest-xdist
Errors
Common errors & fixes
pytest: error: unrecognized arguments: --nunitxml=report.xml
The pytest-nunit plugin is not installed or not active in the current Python environment, so pytest does not recognize its specific command-line options.
fix
Install the plugin using `pip install pytest-nunit` in your active virtual environment.
pytest: error: argument --nunitxml: expected one argument
The `--nunitxml` option requires a filename to specify where the NUnit XML report should be saved, but no filename was provided.
fix
Provide a filename after `--nunitxml`, for example: `pytest --nunitxml=test_results.xml`.
ModuleNotFoundError: No module named 'pytest_nunit'
pytest-nunit is a pytest plugin designed to be loaded by pytest automatically, and its internal modules are not typically intended for direct import by users.
fix
You generally do not need to import `pytest_nunit`. To use the plugin, ensure it's installed (`pip install pytest-nunit`) and run `pytest` with the `--nunitxml` option.
Upgrade
Version history
1.0.7latest on PyPI · released Feb 26, 2024
Audit
Dependencies
pytestrequiredCore testing framework. Requires pytest >= 5.1.0.
pythonrequiredRequires Python >= 3.7.
xmlschemarequiredAdded as a dependency in version 1.0.2 for XML validation and schema handling.
Agent activity
5 hits · last 30 days
node
4
Resources
pytest-nunit — pip install pytest-nunit · libregistry