Running python unit tests using nose.
This plugin requires Grunt > 0.4.1 to be installed.
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-nose --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-nose');
In your project's Gruntfile, add a section named nose
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
nose: {
options: {
// Task-specific options go here.
},
your_target: {
// Target-specific file lists and/or options go here.
},
},
})
The nose
task accepts all the same options as the nose CLI does. If you want to run nose with any additional plugins (like coverage or similar), you must install them separately, either into your system environment or into a virtualenv, and run the grunt task in the virtualenv.
Type: Boolean
Default: false
Be more verbose.
Type: Boolean
Default: false
Be less verbose.
Type: String
or Array
Load configuration from config file(s). May be specified multiple times; in that case, all config files will be loaded and combined
Type: String
Look for tests in this directory under Python 3.x. Functions the same as 'where', but only applies if running under Python 3.x or above. Note that, if present under 3.x, this option completely replaces any directories specified with 'where', so the 'where' option becomes ineffective.
Type: String
Default: "(?:^|[\b_./-])[Tt]est"
Files, directories, function names, and class names that match this regular expression are considered tests.
Type: Array
Default: Runs all tests found
Run these tests (the array should be names of modules), and no others.
Type: Array
or String
Activate debug logging for one or more systems. Available debug loggers: nose, nose.importer, nose.inspector, nose.plugins, nose.result and nose.selector.
Type: String
Default: sys.stderr
Log debug messages to this file.
Type: String
Load logging config from this file -- bypasses all other logging config settings.
Type: String
or Array
Completely ignore any file that matches this regular expression. Takes precedence over any other settings or plugins. Specifying this option will replace the default setting. Specify this option as an array to add more regular expressions.
Type: String
Don't run tests that match regular expression
Type: String
or Array
This regular expression will be applied to files, directories, function names, and class names for a chance to include additional tests that do not match options.match
. Specify this option as an array to add more regular expressions.
Type: Boolean
Default: false
Stop running tests after the first error or failure
Type: Boolean
Default: false
Don't make any changes to sys.path when loading tests
Type: Boolean
Default: false
Look for tests in python modules that are executable. Normal behavior is to exclude executable modules, since they may not be import-safe.
Type: Boolean
DO NOT look for tests in python modules that are executable. (The default on the windows platform is to do so.)
Type: Boolean
Default: false
Traverse through all path entries of a namespace package.
Type: Boolean
Default: false
nose's importer will normally evict a package from sys.modules if it sees a package with the same name in a different location. Set this option to disable that behavior.
Type: Boolean
default: false
Prevent nose from byte-compiling the source into .pyc files while nose is scanning for and running tests.
Type: String
Run only tests that have attributes specified by attr
.
Type: String
Run only tests for whose attributes the Python expression EXPR evaluates to True.
Type: Boolean
Default: false
Don't capture stdout (any stdout output will be printed immediately).
Type: Boolean
Default: false
Disable logging capture plugin. Logging configurtion will be left intact.
Type: String
Specify custom format to print statements. Uses the same format as used by standard logging handlers.
Type: String
Specify custom date/time format to print statements. Uses the same format as used by standard logging handlers.
Type: String
Specify which statements to filter in/out. By default, everything is captured. If the output is too verbose, use this option to filter out needless output. Example: filter=foo will capture statements issued ONLY to foo or foo.what.ever.sub but not foobar or other logger. Specify multiple loggers with comma: filter=foo,bar,baz. If any logger name is prefixed with a minus, eg filter=-foo, it will be excluded rather than included. Default: exclude logging messages from nose itself (-nose). Can also be specified by envvar NOSE_LOGFILTER.
Type: Boolean
Default: false
Clear all other logging handlers
Type: String
Default: 'DEBUG'
Set the log level to capture
Type: Boolean
Default: false
Enable plugin Coverage: Activate a coverage report using Ned Batchelder's coverage module. Requires coverage to be installed separetly, f. ex in a virtualenv specified by options.virtualenv
.
Type: String
Default: All packages
Restrict coverage output to selected packages
Type: Boolean
Default: false
Erase previously collected coverage statistics before run.
Type: Boolean
Default: false
Include test modules in coverage report.
Type: Number
Default: 0
Minimum percentage of coverage for tests to pass.
Type: Boolean
Default: false
Include all python files under working directory in coverage report. Useful for discovering holes in test coverage if not all files are imported by the test suite.
Type: Boolean
Default: false
Produce HTML coverage information.
Type: String
Produce HTML coverage information in dir.
Type: Boolean
Default: false
Include branch coverage in coverage report.
Type: Boolean
Default: false
Produce XML coverage information.
Type: String
Produce XML coverage information in file.
Type: Boolean
Default: false
Drop into debugger on errors. Pass in a EOF to end the session (Ctrl+D on Mac).
Type: Boolean
Default: false
Drop into debugger on failures.
Type: Boolean
Default: false
Disable special handling of DeprecatedTest exceptions.
Type: Boolean
Default: false
Enable plugin Doctest: Activate doctest plugin tofind and run doctests in non-test modules.
Type: Boolean
Default: false
Also look for doctests in test modules. Note that classes, methods and functions should have either doctests or non-doctest tests, not both.
Type: String
Default: false
Also look for doctests in files with this extension.
Type: String
Change the variable name set to the result of the last interpreter command from the default '_'. Can be used to avoid conflicts with the _() function used for text translation.
Type: String
Find fixtures for a doctest file in module with this name appended to the base name of the doctest file.
Type: String
Specify options to pass to doctest. Eg. '+ELLIPSIS,+NORMALIZE_WHITESPACE'.
Type: Boolean
Default: false
Enable plugin IsolationPlugin: Activate the isolation plugin to isolate changes to external modules to a single test module or package. The isolation plugin resets the contents of sys.modules after each test module or package runs to its state before the test. PLEASE NOTE that this plugin should not be used with the coverage plugin, or in any other case where module reloading may produce undesirable side-effects.
Type: Boolean
Default: false
Add detail to error output by attempting to evaluate failed asserts.
Type: Boolean
Default: false
Enable plugin Profile: Use this plugin to run tests using the hotshot profiler.
Type: String
Set sort order for profiler output.
Type: String
Profiler stats file; default is a new temp file on each run.
Type: String
Restrict profiler output. See help for pstats.Stats for details.
Type: Boolean
Default: false
Disable special handling of SkipTest exceptions.
Type: Boolean
Default: false
Enable plugin TestId: Activate to add a test id (like #1) to each test name output. Activate with options.failed
to rerun failing tests only.
Type: String
Store test ids found in test runs in this file. Default is the file .noseids in the working directory.
Type: Boolean
Default: false
Run the tests that failed in the last test run.
Type: Number
Default: 0
Spread test run among this many processes. Set a number equal to the number of processors or cores in your machine for best results. Pass a negative number to have the number of processes automatically set to the number of cores. Passing 0 means to disable parallel testing. Default is 0 unless NOSE_PROCESSES is set.
Type: Number
Default: 10
Set timeout for return of results from each test runner process.
Type: Boolean
Default: false
If set, will restart each worker process once their tests are done, this helps control memory leaks from killing the system.
Type: String
Run the unit tests in this virtualenv.
Type: Boolean
Default: false
Use nose modules from python interpreter in path.
Type: Boolean
Default: false
Enable plugin Xunit: This plugin provides test results in the standard XUnit XML format.
Type: String
Default: 'nosetests.xml'
Path to xml file to store the xunit report in.
Type: Boolean
Default: false
Enable plugin AllModules: Collect tests from all python modules.
Type: Boolean
Default: false
Enable collect-only: Collect and output test names only, don't run any tests.
In the simplest case, run nose without any arguments at all. This would make nose scan for tests, and execute whatever it finds.
grunt.initConfig({
nose: {
main: { }
},
})
A bit more practical though is to utilize some of the power of nose, so if we want code coverage in HTML, we're writing doctests, and we'd like to see the results as a XUnit report, do the following: (note that coverage must be installed separatly, f. ex in a virtualenv specified by options.virtualenv
)
grunt.initConfig({
nose: {
options: {
virtualenv: 'my_app_venv',
with_coverage: true,
cover_package: "mypackage",
cover_branches: true,
cover_xml: true,
coverage_html: true,
coverage_html_dir: 'code_coverage',
with_doctest: true,
with_xunit: true,
},
},
})
To fetch the nose libs, run npm run-script devsetup
, that should install everything you need.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
- Remove peer dependency on grunt
- Update bundled nose to 1.3.7
- Make compatible with grunt 1.0
- Enable loading tests from several directories (issue #11)
- Update bundled nose to 1.3.4
Use python executable from virtualenvs.
Fix bug with the 'config' option.
Remove grunt.util._-usage.
Add option externalNose to not use the included nose.
Distribute nose source along with the grunt-nose.