nose: nose.commands
You can run tests using the nosetests setuptools command:
python setup.py nosetests
This command has one benefit over the standard test command: all nose plugins are supported.
To configure the nosetests command, add a [nosetests] section to your setup.cfg. The [nosetests] section can contain any command line arguments that nosetests supports. The differences between issuing an option on the command line and adding it to setup.cfg are:
- In setup.cfg, the -- prefix must be excluded
- In setup.cfg, command line flags that take no arguments must be given an argument flag (1, T or TRUE for active, 0, F or FALSE for inactive)
Here's an example [nosetests] setup.cfg section:
[nosetests] verbosity=1 detailed-errors=1 with-coverage=1 cover-package=nose debug=nose.loader pdb=1 pdb-failures=1
If you commonly run nosetests with a large number of options, using the nosetests setuptools command and configuring with setup.cfg can make running your tests much less tedious. (Note that the same options and format supported in setup.cfg are supported in all other config files, and the nosetests script will also load config files.)
Another reason to run tests with the command is that the command will install packages listed in your tests_require, as well as doing a complete build of your package before running tests. For packages with dependencies or that build C extensions, using the setuptools command can be more convenient than building by hand and running the nosetests script.
Classes
Highlighted methods are defined in this class.
Methods
If the current verbosity level is of greater than or equal to 'level' print 'msg' to stdout.
Copy a file respecting verbose, dry-run and force flags. (The former two default to whatever is in the Distribution object, and the latter defaults to false for commands that don't define it.)
Copy an entire directory tree respecting verbose, dry-run, and force flags.
Print 'msg' to stdout if the global DEBUG (taken from the DISTUTILS_DEBUG environment variable) flag is true.
Ensure that 'option' is the name of an existing file.
Ensure that 'option' is a string; if not defined, set it to 'default'.
Ensure that 'option' is a list of strings. If 'option' is currently a string, we split it either on /,s*/ or /s+/, so "foo bar baz", "foo,bar,baz", and "foo, bar baz" all become ["foo", "bar", "baz"].
nothing to do here
Wrapper around Distribution's 'get_command_obj()' method: find (create if necessary and 'create' is true) the command object for 'command', call its 'ensure_finalized()' method, and return the finalized command object.
Determine the sub-commands that are relevant in the current distribution (ie., that need to be run). This is based on the 'sub_commands' class attribute: each tuple in that list may include a method that we call to determine if the subcommand needs to be run for the current distribution. Return a list of command names.
create the member variables, but change hyphens to underscores
Special case of 'execute()' for operations that process one or more input files and generate one output file. Works just like 'execute()', except the operation is skipped and a different message printed if 'outfile' already exists and is newer than all files listed in 'infiles'. If the command defined 'self.force', and it is true, then the command is unconditionally run -- does no timestamp checks.
Move a file respectin dry-run flag.
ensure tests are capable of being run, then run nose.main with a reconstructed argument list
Run some other command: uses the 'run_command()' method of Distribution, which creates and finalizes the command object if necessary and then invokes its 'run()' method.
Set the values of any "undefined" options from corresponding option values in some other command object. "Undefined" here means "is None", which is the convention used to indicate that an option has not been changed between 'initialize_options()' and 'finalize_options()'. Usually called from 'finalize_options()' for options that depend on some other command rather than another option of the same command. 'src_cmd' is the other command from which option values will be taken (a command object will be created for it if necessary); the remaining arguments are '(src_option,dst_option)' tuples which mean "take the value of 'src_option' in the 'src_cmd' command object, and copy it to 'dst_option' in the current command object".
Spawn an external command respecting dry-run flag.
Attributes
Default value: Config(addPaths=True, args=(), configSection='nosetests', debug=None, debugLog=None, env={}, exclude=None, files=[], getTestCaseNamesCompat=False, ignoreFiles=(<_sre.SRE_Pattern object>, <_sre.SRE_Pattern object>, <_sre.SRE_Pattern object>), include=None, includeExe=False, logStream=<open file '<stderr>', mode 'w'>, loggingConfig=None, options=<nose.config.NoOptions object>, parser=<optparse.OptionParser instance>, plugins=<nose.plugins.manager.DefaultPluginManager object>, runOnInit=True, srcDirs=('lib', 'src'), stopOnError=False, stream=<open file '<stderr>', mode 'w'>, testMatch=<_sre.SRE_Pattern object>, testMatchPat='(?:^|[\\b_\\./-])[Tt]est', testNames=[], verbosity=1, where=(), workingDir='/tmp/nose_rel_0.10.1')
Default value: <optparse.OptionParser instance>
Default value: False
Default value: Run unit tests using nosetests
Default value: []
Default value: [('version', 'V', 'Output nose version and exit'), ('plugins', 'p', 'Output list of available plugins and exit. Combine with higher verbosity for greater detail'), ('verbosity=', None, 'Set verbosity; --verbosity=2 is the same as -v'), ('quiet=', 'q', ''), ('config=', 'c', 'Load configuration from config file(s). May be specified multiple times; in that case, all config files will be loaded and combined'), ('where=', 'w', 'Look for tests in this directory. May be specified multiple times. The first directory passed will be used as the working directory, in place of the current working directory, which is the default. Others will be added to the list of tests to execute. [NOSE_WHERE]'), ('match=', 'm', 'Use this regular expression to find tests [NOSE_TESTMATCH]'), ('tests=', None, 'Run these tests (comma-separated list). This argument is useful mainly from configuration files; on the command line, just pass the tests to run as additional arguments with no switch.'), ('debug=', 'l', 'Activate debug logging for one or more systems. Available debug loggers: nose, nose.importer, nose.inspector, nose.plugins, nose.result and nose.selector. Separate multiple names with a comma.'), ('debug-log=', None, 'Log debug messages to this file (default: sys.stderr)'), ('logging-config=', None, 'Load logging config from this file -- bypasses all other logging config settings.'), ('exclude=', 'e', "Don't run tests that match regular expression [NOSE_EXCLUDE]"), ('include=', 'i', 'Also run tests that match regular expression [NOSE_INCLUDE]'), ('stop', 'x', 'Stop running tests after the first error or failure'), ('no-path-adjustment', 'P', "Don't make any changes to sys.path when loading tests [NOSE_NOPATH]"), ('exe', None, 'Look for tests in python modules that are executable. Normal behavior is to exclude executable modules, since they may not be import-safe [NOSE_INCLUDE_EXE]'), ('noexe', None, 'DO NOT look for tests in python modules that are executable. (The default on the windows platform is to do so.)'), ('attr=', 'a', 'Run only tests that have attributes specified by ATTR [NOSE_ATTR]'), ('eval-attr=', 'A', 'Run only tests for whose attributes the Python expression EXPR evaluates to True [NOSE_EVAL_ATTR]'), ('nocapture', 's', "Don't capture stdout (any stdout output will be printed immediately) [NOSE_NOCAPTURE]"), ('with-coverage', None, "Enable plugin Coverage: \nIf you have Ned Batchelder's coverage module installed, you may\nactivate a coverage report. The coverage report will cover any\npython source module imported after the start of the test run, excluding\nmodules that match testMatch. If you want to include those modules too,\nuse the --cover-tests switch, or set the NOSE_COVER_TESTS environment\nvariable to a true value. To restrict the coverage report to modules from\na particular package or packages, use the --cover-packages switch or the\nNOSE_COVER_PACKAGES environment variable.\n [NOSE_WITH_COVERAGE]"), ('cover-package=', None, 'Restrict coverage output to selected packages [NOSE_COVER_PACKAGE]'), ('cover-erase', None, 'Erase previously collected coverage statistics before run'), ('cover-tests', None, 'Include test modules in coverage report [NOSE_COVER_TESTS]'), ('cover-inclusive', None, '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. [NOSE_COVER_INCLUSIVE]'), ('pdb', None, 'Drop into debugger on errors'), ('pdb-failures', None, 'Drop into debugger on failures'), ('no-deprecated', None, 'Disable special handling of DeprecatedTest exceptions.'), ('with-doctest', None, 'Enable plugin Doctest: \nActivate doctest plugin to find and run doctests in non-test modules.\n [NOSE_WITH_DOCTEST]'), ('doctest-tests', None, 'Also look for doctests in test modules. Note that classes, methods and functions should have either doctests or non-doctest tests, not both. [NOSE_DOCTEST_TESTS]'), ('doctest-extension=', None, 'Also look for doctests in files with this extension [NOSE_DOCTEST_EXTENSION]'), ('with-isolation', None, 'Enable plugin IsolationPlugin: \nActivate the isolation plugin to isolate changes to external\nmodules to a single test module or package. The isolation plugin\nresets the contents of sys.modules after each test module or\npackage runs to its state before the test. PLEASE NOTE that this\nplugin should not be used with the coverage plugin in any other case\nwhere module reloading may produce undesirable side-effects.\n [NOSE_WITH_ISOLATION]'), ('detailed-errors', 'd', 'Add detail to error output by attempting to evaluate failed asserts [NOSE_DETAILED_ERRORS]'), ('with-profile', None, 'Enable plugin Profile: \nUse this plugin to run tests using the hotshot profiler. \n [NOSE_WITH_PROFILE]'), ('profile-sort=', None, 'Set sort order for profiler output'), ('profile-stats-file=', None, 'Profiler stats file; default is a new temp file on each run'), ('profile-restrict=', None, 'Restrict profiler output. See help for pstats.Stats for details'), ('no-skip', None, 'Disable special handling of SkipTest exceptions.'), ('with-id', None, "Enable plugin TestId: \nActivate to add a test id (like #1) to each test name output. After\nyou've run once to generate test ids, you can re-run individual\ntests by activating the plugin and passing the ids (with or\nwithout the # prefix) instead of test names.\n [NOSE_WITH_ID]"), ('id-file=', None, 'Store test ids found in test runs in this file. Default is the file .noseids in the working directory.')]
Functions
convert a optparse option list into a distutils option tuple list
Attributes
Default value: ['help', 'verbose']