{"id":5431,"library":"pytest-nunit","title":"pytest-nunit","description":"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.","status":"active","version":"1.0.7","language":"en","source_language":"en","source_url":"https://github.com/pytest-dev/pytest-nunit","tags":["pytest-plugin","testing","nunit","xml-report","ci"],"install":[{"cmd":"pip install pytest-nunit","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core testing framework. Requires pytest >= 5.1.0.","package":"pytest","optional":false},{"reason":"Requires Python >= 3.7.","package":"python","optional":false},{"reason":"Added as a dependency in version 1.0.2 for XML validation and schema handling.","package":"xmlschema","optional":false}],"imports":[],"quickstart":{"code":"import pytest\n\n# Create a dummy test file, e.g., test_example.py\nwith open('test_example.py', 'w') as f:\n    f.write('def test_success():\\n    assert True\\n\\ndef test_failure():\\n    assert False\\n')\n\n# Run pytest with nunitxml output\n# This will generate a 'test-results.xml' file in the current directory\npytest.main(['test_example.py', '--nunit-xml=test-results.xml'])\n\n# Clean up (optional)\nimport os\nos.remove('test_example.py')\nos.remove('test-results.xml')","lang":"python","description":"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`."},"warnings":[{"fix":"Upgrade to `pytest-nunit` version 1.0.7 or later to ensure compatibility with `pytest` 8.x series.","message":"Older 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.","severity":"breaking","affected_versions":"<1.0.7"},{"fix":"Update `pytest-nunit` to version 1.0.6 or newer to use `datetime.now(timezone.utc)` and avoid `utcnow()` deprecation warnings.","message":"The `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.","severity":"deprecated","affected_versions":"<1.0.6"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":"All versions >=1.0.2"},{"fix":"Always include `--nunit-xml=your_report_file.xml` when invoking `pytest` to ensure the report is generated.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Avoid using the `nunit_suite_name` INI option as it has no effect.","message":"The `nunit_suite_name` INI option is deprecated and its value is ignored by `pytest-nunit`.","severity":"deprecated","affected_versions":"All versions"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":"All versions when used with pytest-xdist"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}