A pytest plugin for generating NUnit3 test result XML output
Requires: - Pytest 4.6+ - Python 3.6+
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.
A string value to prefix all test case names the string provided.
Defaults to an empty string.
Boolean value to include the system username in the test run properties.
Defaults to false
Boolean value to include the system user domain in the test run properties.
Defaults to false
(Deprecated, value ignored)
String value to set the test suite name.
Defaults to 'pytest'
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 casesfail
- Include test attachments for only failed test cases
The following fixtures are made available by this plugin.
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 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
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 will have the reason
attribute (if provided) included in the results.
Using the add_nunit_attachment
fixture will render any attachments in the "attachments" tab inside the Tests console:
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.
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
- fix unicode escapes in cdata (#39)
- fix start/stop time calculation (#42)
- dropping support for python3.4 (#45)
- dropping support for old xdist versions (#44)
- Bugfix - Fix time taken for tests under certain scenarios causing crash on pytest_sessionfinish
- Bugfix - Escape tabbed unicode characters from stdout feed from being in CDATA output
- Bugfix - Fixed cause of crash for tests that could be discovered but never executed
- Docstrings of nodes (functions) are set as the label for TestCase elements (contribution by @mikeattara)
- Pytest -k keyword filters are added to the test run filter element under
name
. - Pytest -m marker filters are added to the test run filter element under
namespace
. - Any path filters are added to the test run filter element under
test
. - Each Python module containing tests is now a separate
test-suite
element, instead of having one large suite - Docstrings of modules are set as the label for TestSuite elements
- 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.
- Added
--nunit-prefix
option.
- First stable release