Test runner and main()

Implements nose test program and collector.

class nose.core.TestProgram(module=None, defaultTest='.', argv=None, testRunner=None, testLoader=None, env=None, config=None, suite=None, exit=True, plugins=None, addplugins=None)

Collect and run tests, returning success or failure.

The arguments to TestProgram() are the same as to main() and run():

  • module: All tests are in this module (default: None)

  • defaultTest: Tests to load (default: ‘.’)

  • argv: Command line arguments (default: None; sys.argv is read)

  • testRunner: Test runner instance (default: None)

  • testLoader: Test loader instance (default: None)

  • env: Environment; ignored if config is provided (default: None; os.environ is read)

  • config: nose.config.Config instance (default: None)

  • suite: Suite or list of tests to run (default: None). Passing a suite or lists of tests will bypass all test discovery and loading. ALSO NOTE that if you pass a unittest.TestSuite instance as the suite, context fixtures at the class, module and package level will not be used, and many plugin hooks will not be called. If you want normal nose behavior, either pass a list of tests, or a fully-configured nose.suite.ContextSuite.

  • exit: Exit after running tests and printing report (default: True)

  • plugins: List of plugins to use; ignored if config is provided (default: load plugins with DefaultPluginManager)

  • addplugins: List of extra plugins to use. Pass a list of plugin instances in this argument to make custom plugins available while still using the DefaultPluginManager.

createTests()

Create the tests to run. If a self.suite is set, then that suite will be used. Otherwise, tests will be loaded from the given test names (self.testNames) using the test loader.

makeConfig(env, plugins=None)

Load a Config, pre-filled with user config files if any are found.

parseArgs(argv)

Parse argv and env and configure running environment.

runTests()

Run Tests. Returns true on success, false on failure, and sets self.success to the same value.

showPlugins()

Print list of available plugins.

nose.core.main

alias of nose.core.TestProgram

nose.core.run(*arg, **kw)

Collect and run tests, returning success or failure.

The arguments to run() are the same as to main():

  • module: All tests are in this module (default: None)

  • defaultTest: Tests to load (default: ‘.’)

  • argv: Command line arguments (default: None; sys.argv is read)

  • testRunner: Test runner instance (default: None)

  • testLoader: Test loader instance (default: None)

  • env: Environment; ignored if config is provided (default: None; os.environ is read)

  • config: nose.config.Config instance (default: None)

  • suite: Suite or list of tests to run (default: None). Passing a suite or lists of tests will bypass all test discovery and loading. ALSO NOTE that if you pass a unittest.TestSuite instance as the suite, context fixtures at the class, module and package level will not be used, and many plugin hooks will not be called. If you want normal nose behavior, either pass a list of tests, or a fully-configured nose.suite.ContextSuite.

  • plugins: List of plugins to use; ignored if config is provided (default: load plugins with DefaultPluginManager)

  • addplugins: List of extra plugins to use. Pass a list of plugin instances in this argument to make custom plugins available while still using the DefaultPluginManager.

With the exception that the exit argument is always set to False.

nose.core.run_exit

alias of nose.core.TestProgram

nose.core.runmodule(name='__main__', **kw)

Collect and run tests in a single module only. Defaults to running tests in __main__. Additional arguments to TestProgram may be passed as keyword arguments.

nose.core.collector()

TestSuite replacement entry point. Use anywhere you might use a unittest.TestSuite. The collector will, by default, load options from all config files and execute loader.loadTestsFromNames() on the configured testNames, or ‘.’ if no testNames are configured.

class nose.core.TextTestRunner(stream=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, descriptions=1, verbosity=1, config=None)

Test runner that uses nose’s TextTestResult to enable errorClasses, as well as providing hooks for plugins to override or replace the test output stream, results, and the test case itself.

run(test)

Overrides to provide plugin hooks and defer all output to the test result class.