NOSETESTS(1)
β¨ NOSETESTS(1) β¨
the <code>nose</code> manual page π«Ά aka the nicer-testing-for-Python girlies' bible
π NAME π
nosetests β Nicer testing for Python π
πΈ NICER TESTING FOR PYTHON πΈ
β¨ SYNOPSIS β¨
nosetests [options] [names]
π¦ DESCRIPTION π¦
okay so bestie, here's the tea π β nose collects tests automatically from python source files, directories and packages it finds in its working directory (and yeah, that defaults to the current working directory, no cap). Any python source file, directory or package that matches the testMatch regular expression gets collected as a test (or as a source for collecting tests). The default testMatch is:
(?:^|[b_.-])[Tt]est
and also? Every other package chillin' in the working directory gets examined for python source files or directories that match testMatch too. Package discovery descends all the way down the tree β like, package.tests and package.sub.tests and package.sub.sub2.tests will all be collected. it's giving thorough π
Within a test directory or package, any python source file matching testMatch will be examined for test cases. Within a test module, functions and classes whose names match testMatch, plus TestCase subclasses with any name, get loaded and executed as tests. Tests may use the assert keyword or raise AssertionErrors to indicate test failure. TestCase subclasses may do the same, or use the various TestCase methods available. iconic behavior honestly π
β οΈ IMPORTANT SIS: the default behavior of nose is to not include tests from files which are executable. To include tests from such files, remove their executable bit or use the --exe flag (see the Options section below). don't say I didn't warn you π
π Selecting Tests π
To specify which tests to run, pass test names on the command line:
nosetests only_test_this.py
Test names specified may be file or module names, and may optionally indicate the test case to run by separating the module or file name from the test case name with a colon. Filenames may be relative or absolute. Examples, periodt:
nosetests test.module
nosetests another.test:TestCase.test_method
nosetests a.test:TestCase
nosetests /path/to/test/file.py:test_function
You may also change the working directory where nose looks for tests by using the -w switch:
nosetests -w /path/to/tests
π¨ but heads up: support for multiple-warguments is now deprecated and will be removed in a future release. As of nose 0.10, you can get the same behavior by specifying the target directories without the-wswitch:
nosetests /path/to/tests /another/path/to/tests
Further customization of test selection and loading is possible through the use of plugins π§
Test result output is identical to that of unittest, except for the additional features (error classes, and plugin-supplied features such as output capture and assert introspection) detailed in the options below. same energy, extra sparkle β¨
π Configuration π
In addition to passing command-line options, you may also put configuration options in your project's setup.cfg file, or a .noserc or nose.cfg file in your home directory π In any of these standard ini-style config files, you put your nosetests configuration in a [nosetests] section. Options are the same as on the command line, with the -- prefix removed. For options that are simple switches, you must supply a value:
[nosetests]
verbosity=3
with-doctest=1
All configuration files that are found will be loaded and their options combined. You can override the standard config file loading with the -c option. so much power π
π Using Plugins π
There are numerous nose plugins available via easy_install and elsewhere. To use a plugin, just install it. The plugin will add command line options to nosetests. To verify that the plugin is installed, run:
nosetests --plugins
You can add -v or -vv to that command to show more information about each plugin. slay π«Ά
If you are running nose.main() or nose.run() from a script, you can specify a list of plugins to use by passing a list of plugins with the plugins keyword argument.
π§ 0.9 plugins
nose 1.0 can use SOME plugins that were written for nose 0.9. The default plugin manager inserts a compatibility wrapper around 0.9 plugins that adapts the changed plugin api calls. However β and this is the part where it gets a little rough π β plugins that access nose internals are likely to fail, especially if they attempt to access test case or test suite classes. For example, plugins that try to determine if a test passed to startTest is an individual test or a suite will fail, partly because suites are no longer passed to startTest and partly because it's likely that the plugin is trying to find out if the test is an instance of a class that no longer exists. π
π 0.10 and 0.11 plugins
All plugins written for nose 0.10 and 0.11 should work with nose 1.0. no cap, they're fine π
π Options π
-V,--versionβ Output nose version and exit-p,--pluginsβ Output list of available plugins and exit. Combine with higher verbosity for greater detail-v=DEFAULT,--verbose=DEFAULTβ Be more verbose. [NOSE_VERBOSE]--verbosity=VERBOSITYβ Set verbosity;--verbosity=2is the same as-v-q=DEFAULT,--quiet=DEFAULTβ Be less verbose-c=FILES,--config=FILESβ Load configuration from config file(s). May be specified multiple times; in that case, all config files will be loaded and combined-w=WHERE,--where=WHEREβ 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]--py3where=PY3WHEREβ Look for tests in this directory under Python 3.x. Functions the same aswhere, 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 withwhere, so thewhereoption becomes ineffective. [NOSE_PY3WHERE]-m=REGEX,--match=REGEX,--testmatch=REGEXβ Files, directories, function names, and class names that match this regular expression are considered tests. Default:(?:^|[b_./-])[Tt]est[NOSE_TESTMATCH]--tests=NAMESβ 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.-l=DEFAULT,--debug=DEFAULTβ Activate debug logging for one or more systems. Available debug loggers:nose,nose.importer,nose.inspector,nose.plugins,nose.resultandnose.selector. Separate multiple names with a comma.--debug-log=FILEβ Log debug messages to this file (default:sys.stderr)--logging-config=FILE,--log-config=FILEβ Load logging config from this file β bypasses all other logging config settings.-I=REGEX,--ignore-files=REGEXβ 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 multiple times to add more regular expressions [NOSE_IGNORE_FILES]-e=REGEX,--exclude=REGEXβ Don't run tests that match regular expression [NOSE_EXCLUDE]-i=REGEX,--include=REGEXβ This regular expression will be applied to files, directories, function names, and class names for a chance to include additional tests that do not matchTESTMATCH. Specify this option multiple times to add more regular expressions [NOSE_INCLUDE]-x,--stopβ Stop running tests after the first error or failure-P,--no-path-adjustmentβ Don't make any changes tosys.pathwhen loading tests [NOSE_NOPATH]--exeβ 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β DO NOT look for tests in python modules that are executable. (The default on the windows platform is to do so.)--traverse-namespaceβ Traverse through all path entries of a namespace package--first-package-wins,--first-pkg-wins,--1st-pkg-winsβ nose's importer will normally evict a package fromsys.modulesif it sees a package with the same name in a different location. Set this option to disable that behavior.--no-byte-compileβ Prevent nose from byte-compiling the source into.pycfiles while nose is scanning for and running tests.-a=ATTR,--attr=ATTRβ Run only tests that have attributes specified byATTR[NOSE_ATTR]-A=EXPR,--eval-attr=EXPRβ Run only tests for whose attributes the Python expressionEXPRevaluates toTrue[NOSE_EVAL_ATTR]-s,--nocaptureβ Don't capture stdout (any stdout output will be printed immediately) [NOSE_NOCAPTURE]--nologcaptureβ Disable logging capture plugin. Logging configuration will be left intact. [NOSE_NOLOGCAPTURE]--logging-format=FORMATβ Specify custom format to print statements. Uses the same format as used by standard logging handlers. [NOSE_LOGFORMAT]--logging-datefmt=FORMATβ Specify custom date/time format to print statements. Uses the same format as used by standard logging handlers. [NOSE_LOGDATEFMT]--logging-filter=FILTERβ 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=foowill capture statements issued ONLY tofooorfoo.what.ever.subbut notfoobaror other logger. Specify multiple loggers with comma:filter=foo,bar,baz. If any logger name is prefixed with a minus, egfilter=-foo, it will be excluded rather than included. Default: exclude logging messages from nose itself (-nose). [NOSE_LOGFILTER]--logging-clear-handlersβ Clear all other logging handlers--logging-level=DEFAULTβ Set the log level to capture--with-coverageβ Enable plugin Coverage: Activate a coverage report using Ned Batchelder's coverage module. [NOSE_WITH_COVERAGE]--cover-package=PACKAGEβ Restrict coverage output to selected packages [NOSE_COVER_PACKAGE]--cover-eraseβ Erase previously collected coverage statistics before run--cover-testsβ Include test modules in coverage report [NOSE_COVER_TESTS]--cover-min-percentage=DEFAULTβ Minimum percentage of coverage for tests to pass [NOSE_COVER_MIN_PERCENTAGE]
to be continued bestieβ¦ more of this page is coming π
--cover-inclusiveβ bestie this one scoops up every single python file chilling under your working directory and drags them into the coverage report. it's giving detective energy π β lowkey the best way to spot holes in your coverage when your test suite isn't even importing all your files.[NOSE_COVER_INCLUSIVE]--cover-htmlβ produce HTML coverage info β¨ cute little clickable report, we love to see it.--cover-html-dir=DIRβ same HTML coverage tea but drop it in DIR π--cover-branchesβ now we're including branch coverage in the report, not just line coverage. main character coverage fr.[NOSE_COVER_BRANCHES]--cover-xmlβ produce XML coverage info π for the machines, iykyk--cover-xml-file=FILEβ XML coverage info, but in FILE specifically π--pdbβ failures or errors? we're dropping straight into the debugger π no escape, no cap--pdb-failuresβ only drop into the debugger on failures, not errors--pdb-errorsβ only drop into the debugger on errors, not failures--no-deprecatedβ turns OFF the special handling ofDeprecatedTestexceptions. bye special treatment π--with-doctestβ enables the plugin Doctest: turns on the doctest plugin so it goes hunting for and runs doctests inside your non-test modules π΅οΈβοΈ[NOSE_WITH_DOCTEST]--doctest-testsβ also look for doctests inside test modules. β οΈ but bestie, heads up: classes, methods and functions should have either doctests or non-doctest tests, not both. pick a lane π«Ά[NOSE_DOCTEST_TESTS]--doctest-extension=EXTβ also look for doctests in files with this extension, EXT πΈ[NOSE_DOCTEST_EXTENSION]--doctest-result-variable=VARβ changes the variable name that gets set to the result of the last interpreter command. default is'_'. use this when you need to dodge a conflict with the_()function used for text translation π[NOSE_DOCTEST_RESULT_VAR]--doctest-fixtures=SUFFIXβ find fixtures for a doctest file in the module whose name is the doctest file's base name with SUFFIX stuck on the end π--doctest-options=OPTIONSβ pass options straight through to doctest. eg.'+ELLIPSIS,+NORMALIZE_WHITESPACE'β¨--with-isolationβ enables the plugin IsolationPlugin: the isolation plugin isolates changes to external modules down to a single test module or package. it resets the contents ofsys.modulesafter each test module or package runs, back to whatever state it was in before that 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. fr fr do not do it π
[NOSE_WITH_ISOLATION]
-d,--detailed-errors,--failure-detailβ adds detail to your error output by attempting to evaluate the asserts that failed π[NOSE_DETAILED_ERRORS]--with-profileβ enables the plugin Profile: use this one to run your tests with the hotshot profiler π₯[NOSE_WITH_PROFILE]--profile-sort=SORTβ sets the sort order for the profiler output π--profile-stats-file=FILEβ the profiler stats file. default? a fresh new temp file on every single run, iconic behavior π--profile-restrict=RESTRICTβ restricts the profiler output. see the help forpstats.Statsfor the details π--no-skipβ disables the special handling ofSkipTestexceptions. no more skipping, we stay β--with-idβ enables the plugin TestId: activate it and every test name in the output gets a test id like#1. pair it with--failedto rerun only the failing tests π¦[NOSE_WITH_ID]--id-file=FILEβ stores the test ids found during test runs in this file. default is the file.noseidsin the working directory πΈ--failedβ runs the tests that failed in the last test run. round two, let's get it π₯--processes=NUMβ spreads the test run across this many processes. set it equal to your machine's number of processors or cores for best results β¨. pass a negative number and the process count gets automatically set to the number of cores. passing0means parallel testing is disabled. default is0unlessNOSE_PROCESSESis set.[NOSE_PROCESSES]--process-timeout=SECONDSβ sets the timeout for results coming back from each test runner process. default is10.[NOSE_PROCESS_TIMEOUT]--process-restartworkerβ if set, each worker process gets restarted once its tests are done. helps control memory leaks before they kill the whole system π[NOSE_PROCESS_RESTARTWORKER]--with-xunitβ enables the plugin Xunit: delivers test results in the standard XUnit XML format π[NOSE_WITH_XUNIT]--xunit-file=FILEβ path to the xml file where the xunit report goes. default isnosetests.xmlin the working directory π[NOSE_XUNIT_FILE]--xunit-testsuite-name=PACKAGEβ the name of the testsuite in the xunit xml that the plugin generates. default testsuite name isnosetests.[NOSE_XUNIT_FILE]β¦ ok ngl this one's just--xunit-testsuite-name=PACKAGE, no env var listed for it bestie π--all-modulesβ enables the plugin AllModules: collects tests from all python modules π«Ά[NOSE_ALL_MODULES]--collect-onlyβ enables collect-only: collects and outputs the test names only, doesn't run a single test. we're just looking respectfully π[COLLECT_ONLY]
β¨ AUTHOR β¨
Nose developers π
β¨ COPYRIGHT β¨
2009, Jason Pellerin
and that's a wrap bestie π this was nosetests version 1.3, dated April 04, 2015 β go forth and let your tests slay π
β¨
π¦ where this page comes from
- debian bookworm: python3-nose 1.3.7-9 Β· LGPL
- ubuntu jammy: python3-nose 1.3.7-8 Β· LGPL
- ubuntu noble: python3-nose 1.3.7-12 Β· LGPL
- ubuntu resolute: python3-nose 1.3.7-15 Β· LGPL
- ubuntu stonking: python3-nose 1.3.7-15 Β· LGPL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms