NoseXUnit: JUnit like XML reporting for PyUnit
NoseXUnit provide a convenient way to produce JUnit like XML reports with PyUnit. It also provides code coverage and audit features with beautiful reports generation.
NoseXUnit is now compatible with Nose 0.11.1. This version 0.3.3 is mainly a bug fix version. We also added a degraded mode to handle multiprocess test runner (--processes option in nose).
On the one hand, most of complex applications mix different languages and frameworks. On the other hand, test frameworks don't provide standard outputs. This makes difficult to generate an overall report of the tests for your aplication. However, some Java tests frameworks like JUnit with Surefire outputs convenient test report in a simple XML format. This makes further processing simple and convenient for softwares. For example, Hudson and Bamboo creates interesting reports thanks these XML reports.
Our goal is to provide a way to produce test reports in this simple XML format with PyUnit.
NoseXUnit is a plugin for python-nose. Nose is a convenient way to play your PyUnit test.
Install NoseXUnit using setuptools:
NoseXUnit depends on:
- pylint, logilab-common and logilab-astng to check the code,
- coverage for code coverage,
- kid and pygments for reports generations.
Install of logilab-common, logilab-astng and pylint doesn't seem to work properly with setuptools. You may have to download them separately and install them with the old fashioned way before installing NoseXUnit.
Use the nosetests script with --with-nosexunit option:
nosetests --with-nosexunit [options] [(optional) test files or directories]
You can specify (all optionals):
- The XML output folder with --core-target=PATH,
- The folder containing the Python sources with --source-folder=PATH,
- If you want to recursively search source files in source folder to add them in the path with --search-source,
- If you want to recursively search tests that are located outside a package with --search-test,
PyLint audit is enabled with --enable-audit option:
nosetests --with-nosexunit --source-folder=PATH --enable-audit [options] [(optional) test files or directories]
Source folder specification is required. All packages located in this source folder are analyzed. PyLint can't be used with code coverage.
You can specify (all optionals):
- The output folder for report with --audit-target=PATH,
- The type of output with --audit-output=TYPE: nosexunit, html, ... ,
- A PyLint configuration file with --audit-config=PATH.
In source code, you can explicitely ignore an error uncovered by PyLint by using the following tag:
def foo(): exec('a=1') print a # pylint: disable-msg=E0602
Code coverage is enabled with --enable-cover option:
nosetests --with-nosexunit --source-folder=PATH --enable-cover [options] [(optional) test files or directories]
Source folder specification is required. All packages located in this source folder are analyzed. Code coverage can't be used with PyLint.
You can specify (all optionals):
- The output folder for report with --cover-target=PATH,
- If you want to ignore previous executions for coverage with --cover-clean,
- If you want to collect extra coverage files with --cover-collect. These extra coverage files should be generated in the coverage target folder and have the follwing pattern: .coverage.*.
We also generate two extra reports in coverage target folder:
- A Clover style XML report: clover.xml,
- A Cobertura style XML report: cobertura.xml.
In source code, you can explicitely refuse code coverage with:
def foo(): print "hello" # pragma: no cover
Specify packages processed by Audit or Coverage
To explicitely specify packages processed by Audit or Coverage, you can use following options (all optionals):
- --extra-include=PACKAGE to process the specified package,
- --extra-exclude=PACKAGE to do not process the specified package (ez_setup and setup by default, useless if --extra-include specified),
- --extra-test-process to process packages matching the test pattern.
Options --extra-include and --extra-exclude can be specified many times. For example:
nosetests [options] --extra-include foo1 --extra-include foo2
NoseXUnit launch options can be display by running:
nosetests --helpFour options are available:
--with-nosexunit Enable plugin NoseXUnit: Output XML report of test status [NOSE_WITH_NOSEXUNIT] --core-target=CORE_TARGET Output folder for test reports (default is target/NoseXUnit/core). --source-folder=SOURCE Set source folder (optional for core functionality, required for audit and coverage). Add folder in sys.path. --search-source Walk in the source folder to add deeper folders in sys.path if they don't contain __init__.py file. Works only if --source-folder is defined. --search-test Search tests in folders with no __init__.py file (default does nothing). --extra-include=EXTRA_INCLUDE Include packages for audit or coverage processing (default: take all packages in --source-folder, except those defined in --extra-exclude). --extra-exclude=EXTRA_EXCLUDE Exclude packages for audit or coverage processing (default: ez_setup, setup). Useless if --extra-include defined. --extra-test-process Include packages matching the test pattern in audit or coverage processing (default: no). --enable-audit Use PyLint to audit source code (default: no) --audit-target=AUDIT_TARGET Output folder for PyLint reports (default is target/NoseXUnit/audit). --audit-output=AUDIT_OUTPUT Output for audit reports: nosexunit, parseable, text, colorized, html, msvs (default: nosexunit). --audit-config=AUDIT_CONFIG Configuration file for PyLint (optional). --enable-cover Use coverage to audit source code (default: no) --cover-target=COVER_TARGET Output folder for coverage reports (default is target/NoseXUnit/cover). --cover-clean Clean previous coverage results (default: no). --cover-collect Collect other coverage files potentially generated in cover target folder. These extra files should have the following pattern: .coverage.* (default: no).
Please report bugs and make feature requests here.
- Degraded mode for multiprocess test runner (--processes option in nose),
- ID 2738914: Catch all sys.exit of PyLint,
- ID 2784278: Allow unicode strings in standard and error outputs,
- ID 2681443: Allow sources to be read only.
- ID 2184206: Include or exclude packages for audit or coverage (options --extra-include and --extra-exclude),
- Consider or not packages matching the test pattern (option --extra-test-process),
- Audit and coverage can be played together (PyLint started in another process).
- Generate a Clover style XML report,
- Generate a Cobertura style XML report,
- Add --cover-collect to collect extra coverage file.
- Compatibility with nose 0.10.4,
- PyLint reporting,
- Coverage reporting,
- ID 2078051: Support ContextSuite object with no id attribute in Plugin.startTest,
- Option --xml-report-folder replaced by --core-target,
- Option --recursive replaced by --search-source.
- Compatibility with nose 0.10.0a2,
- tb_info and capt removed from XTest (no more available with nose),
- Signature of addSuccess, addFailure and addError modified,
- Entry point modification.
- Compatibility with nose 0.10.0a1,
- Create an XML output for each test module.
- First version.