/README.txt

https://bitbucket.org/jpellerin/nose/ · Plain Text · 494 lines · 317 code · 177 blank · 0 comment · 0 complexity · 9f912c59e35f99bc430010643d0d5c11 MD5 · raw file

  1. Basic usage
  2. ***********
  3. Use the nosetests script (after installation by setuptools):
  4. nosetests [options] [(optional) test files or directories]
  5. In addition to passing command-line options, you may also put
  6. configuration options in a .noserc or nose.cfg file in your home
  7. directory. These are standard .ini-style config files. Put your
  8. nosetests configuration in a [nosetests] section, with the -- prefix
  9. removed:
  10. [nosetests]
  11. verbosity=3
  12. with-doctest=1
  13. There are several other ways to use the nose test runner besides the
  14. *nosetests* script. You may use nose in a test script:
  15. import nose
  16. nose.main()
  17. If you don't want the test script to exit with 0 on success and 1 on
  18. failure (like unittest.main), use nose.run() instead:
  19. import nose
  20. result = nose.run()
  21. *result* will be true if the test run succeeded, or false if any test
  22. failed or raised an uncaught exception. Lastly, you can run nose.core
  23. directly, which will run nose.main():
  24. python /path/to/nose/core.py
  25. Please see the usage message for the nosetests script for information
  26. about how to control which tests nose runs, which plugins are loaded,
  27. and the test output.
  28. Extended usage
  29. ==============
  30. nose collects tests automatically from python source files,
  31. directories and packages found in its working directory (which
  32. defaults to the current working directory). Any python source file,
  33. directory or package that matches the testMatch regular expression (by
  34. default: *(?:^|[b_.-])[Tt]est)* will be collected as a test (or source
  35. for collection of tests). In addition, all other packages found in the
  36. working directory will be examined for python source files or
  37. directories that match testMatch. Package discovery descends all the
  38. way down the tree, so package.tests and package.sub.tests and
  39. package.sub.sub2.tests will all be collected.
  40. Within a test directory or package, any python source file matching
  41. testMatch will be examined for test cases. Within a test module,
  42. functions and classes whose names match testMatch and TestCase
  43. subclasses with any name will be loaded and executed as tests. Tests
  44. may use the assert keyword or raise AssertionErrors to indicate test
  45. failure. TestCase subclasses may do the same or use the various
  46. TestCase methods available.
  47. Selecting Tests
  48. ---------------
  49. To specify which tests to run, pass test names on the command line:
  50. nosetests only_test_this.py
  51. Test names specified may be file or module names, and may optionally
  52. indicate the test case to run by separating the module or file name
  53. from the test case name with a colon. Filenames may be relative or
  54. absolute. Examples:
  55. nosetests test.module
  56. nosetests another.test:TestCase.test_method
  57. nosetests a.test:TestCase
  58. nosetests /path/to/test/file.py:test_function
  59. You may also change the working directory where nose looks for tests
  60. by using the -w switch:
  61. nosetests -w /path/to/tests
  62. Note, however, that support for multiple -w arguments is now
  63. deprecated and will be removed in a future release. As of nose 0.10,
  64. you can get the same behavior by specifying the target directories
  65. *without* the -w switch:
  66. nosetests /path/to/tests /another/path/to/tests
  67. Further customization of test selection and loading is possible
  68. through the use of plugins.
  69. Test result output is identical to that of unittest, except for the
  70. additional features (error classes, and plugin-supplied features such
  71. as output capture and assert introspection) detailed in the options
  72. below.
  73. Configuration
  74. -------------
  75. In addition to passing command-line options, you may also put
  76. configuration options in your project's *setup.cfg* file, or a .noserc
  77. or nose.cfg file in your home directory. In any of these standard
  78. .ini-style config files, you put your nosetests configuration in a
  79. "[nosetests]" section. Options are the same as on the command line,
  80. with the -- prefix removed. For options that are simple switches, you
  81. must supply a value:
  82. [nosetests]
  83. verbosity=3
  84. with-doctest=1
  85. All configuration files that are found will be loaded and their
  86. options combined. You can override the standard config file loading
  87. with the "-c" option.
  88. Using Plugins
  89. -------------
  90. There are numerous nose plugins available via easy_install and
  91. elsewhere. To use a plugin, just install it. The plugin will add
  92. command line options to nosetests. To verify that the plugin is
  93. installed, run:
  94. nosetests --plugins
  95. You can add -v or -vv to that command to show more information about
  96. each plugin.
  97. If you are running nose.main() or nose.run() from a script, you can
  98. specify a list of plugins to use by passing a list of plugins with the
  99. plugins keyword argument.
  100. 0.9 plugins
  101. -----------
  102. nose 1.0 can use SOME plugins that were written for nose 0.9. The
  103. default plugin manager inserts a compatibility wrapper around 0.9
  104. plugins that adapts the changed plugin api calls. However, plugins
  105. that access nose internals are likely to fail, especially if they
  106. attempt to access test case or test suite classes. For example,
  107. plugins that try to determine if a test passed to startTest is an
  108. individual test or a suite will fail, partly because suites are no
  109. longer passed to startTest and partly because it's likely that the
  110. plugin is trying to find out if the test is an instance of a class
  111. that no longer exists.
  112. 0.10 and 0.11 plugins
  113. ---------------------
  114. All plugins written for nose 0.10 and 0.11 should work with nose 1.0.
  115. Options
  116. -------
  117. -V, --version
  118. Output nose version and exit
  119. -p, --plugins
  120. Output list of available plugins and exit. Combine with higher
  121. verbosity for greater detail
  122. -v=DEFAULT, --verbose=DEFAULT
  123. Be more verbose. [NOSE_VERBOSE]
  124. --verbosity=VERBOSITY
  125. Set verbosity; --verbosity=2 is the same as -v
  126. -q=DEFAULT, --quiet=DEFAULT
  127. Be less verbose
  128. -c=FILES, --config=FILES
  129. Load configuration from config file(s). May be specified multiple
  130. times; in that case, all config files will be loaded and combined
  131. -w=WHERE, --where=WHERE
  132. Look for tests in this directory. May be specified multiple times.
  133. The first directory passed will be used as the working directory,
  134. in place of the current working directory, which is the default.
  135. Others will be added to the list of tests to execute. [NOSE_WHERE]
  136. --py3where=PY3WHERE
  137. Look for tests in this directory under Python 3.x. Functions the
  138. same as 'where', but only applies if running under Python 3.x or
  139. above. Note that, if present under 3.x, this option completely
  140. replaces any directories specified with 'where', so the 'where'
  141. option becomes ineffective. [NOSE_PY3WHERE]
  142. -m=REGEX, --match=REGEX, --testmatch=REGEX
  143. Files, directories, function names, and class names that match this
  144. regular expression are considered tests. Default:
  145. (?:^|[b_./-])[Tt]est [NOSE_TESTMATCH]
  146. --tests=NAMES
  147. Run these tests (comma-separated list). This argument is useful
  148. mainly from configuration files; on the command line, just pass the
  149. tests to run as additional arguments with no switch.
  150. -l=DEFAULT, --debug=DEFAULT
  151. Activate debug logging for one or more systems. Available debug
  152. loggers: nose, nose.importer, nose.inspector, nose.plugins,
  153. nose.result and nose.selector. Separate multiple names with a
  154. comma.
  155. --debug-log=FILE
  156. Log debug messages to this file (default: sys.stderr)
  157. --logging-config=FILE, --log-config=FILE
  158. Load logging config from this file -- bypasses all other logging
  159. config settings.
  160. -I=REGEX, --ignore-files=REGEX
  161. Completely ignore any file that matches this regular expression.
  162. Takes precedence over any other settings or plugins. Specifying
  163. this option will replace the default setting. Specify this option
  164. multiple times to add more regular expressions [NOSE_IGNORE_FILES]
  165. -e=REGEX, --exclude=REGEX
  166. Don't run tests that match regular expression [NOSE_EXCLUDE]
  167. -i=REGEX, --include=REGEX
  168. This regular expression will be applied to files, directories,
  169. function names, and class names for a chance to include additional
  170. tests that do not match TESTMATCH. Specify this option multiple
  171. times to add more regular expressions [NOSE_INCLUDE]
  172. -x, --stop
  173. Stop running tests after the first error or failure
  174. -P, --no-path-adjustment
  175. Don't make any changes to sys.path when loading tests [NOSE_NOPATH]
  176. --exe
  177. Look for tests in python modules that are executable. Normal
  178. behavior is to exclude executable modules, since they may not be
  179. import-safe [NOSE_INCLUDE_EXE]
  180. --noexe
  181. DO NOT look for tests in python modules that are executable. (The
  182. default on the windows platform is to do so.)
  183. --traverse-namespace
  184. Traverse through all path entries of a namespace package
  185. --first-package-wins, --first-pkg-wins, --1st-pkg-wins
  186. nose's importer will normally evict a package from sys.modules if
  187. it sees a package with the same name in a different location. Set
  188. this option to disable that behavior.
  189. -a=ATTR, --attr=ATTR
  190. Run only tests that have attributes specified by ATTR [NOSE_ATTR]
  191. -A=EXPR, --eval-attr=EXPR
  192. Run only tests for whose attributes the Python expression EXPR
  193. evaluates to True [NOSE_EVAL_ATTR]
  194. -s, --nocapture
  195. Don't capture stdout (any stdout output will be printed
  196. immediately) [NOSE_NOCAPTURE]
  197. --nologcapture
  198. Disable logging capture plugin. Logging configurtion will be left
  199. intact. [NOSE_NOLOGCAPTURE]
  200. --logging-format=FORMAT
  201. Specify custom format to print statements. Uses the same format as
  202. used by standard logging handlers. [NOSE_LOGFORMAT]
  203. --logging-datefmt=FORMAT
  204. Specify custom date/time format to print statements. Uses the same
  205. format as used by standard logging handlers. [NOSE_LOGDATEFMT]
  206. --logging-filter=FILTER
  207. Specify which statements to filter in/out. By default, everything
  208. is captured. If the output is too verbose, use this option to
  209. filter out needless output. Example: filter=foo will capture
  210. statements issued ONLY to foo or foo.what.ever.sub but not foobar
  211. or other logger. Specify multiple loggers with comma:
  212. filter=foo,bar,baz. If any logger name is prefixed with a minus, eg
  213. filter=-foo, it will be excluded rather than included. Default:
  214. exclude logging messages from nose itself (-nose). [NOSE_LOGFILTER]
  215. --logging-clear-handlers
  216. Clear all other logging handlers
  217. --with-coverage
  218. Enable plugin Coverage: Activate a coverage report using Ned
  219. Batchelder's coverage module. [NOSE_WITH_COVERAGE]
  220. --cover-package=PACKAGE
  221. Restrict coverage output to selected packages [NOSE_COVER_PACKAGE]
  222. --cover-erase
  223. Erase previously collected coverage statistics before run
  224. --cover-tests
  225. Include test modules in coverage report [NOSE_COVER_TESTS]
  226. --cover-inclusive
  227. Include all python files under working directory in coverage
  228. report. Useful for discovering holes in test coverage if not all
  229. files are imported by the test suite. [NOSE_COVER_INCLUSIVE]
  230. --cover-html
  231. Produce HTML coverage information
  232. --cover-html-dir=DIR
  233. Produce HTML coverage information in dir
  234. --cover-branches
  235. Include branch coverage in coverage report [NOSE_COVER_BRANCHES]
  236. --cover-xml
  237. Produce XML coverage information
  238. --cover-xml-file=FILE
  239. Produce XML coverage information in file
  240. --pdb
  241. Drop into debugger on errors
  242. --pdb-failures
  243. Drop into debugger on failures
  244. --no-deprecated
  245. Disable special handling of DeprecatedTest exceptions.
  246. --with-doctest
  247. Enable plugin Doctest: Activate doctest plugin to find and run
  248. doctests in non-test modules. [NOSE_WITH_DOCTEST]
  249. --doctest-tests
  250. Also look for doctests in test modules. Note that classes, methods
  251. and functions should have either doctests or non-doctest tests, not
  252. both. [NOSE_DOCTEST_TESTS]
  253. --doctest-extension=EXT
  254. Also look for doctests in files with this extension
  255. [NOSE_DOCTEST_EXTENSION]
  256. --doctest-result-variable=VAR
  257. Change the variable name set to the result of the last interpreter
  258. command from the default '_'. Can be used to avoid conflicts with
  259. the _() function used for text translation.
  260. [NOSE_DOCTEST_RESULT_VAR]
  261. --doctest-fixtures=SUFFIX
  262. Find fixtures for a doctest file in module with this name appended
  263. to the base name of the doctest file
  264. --with-isolation
  265. Enable plugin IsolationPlugin: Activate the isolation plugin to
  266. isolate changes to external modules to a single test module or
  267. package. The isolation plugin resets the contents of sys.modules
  268. after each test module or package runs to its state before the
  269. test. PLEASE NOTE that this plugin should not be used with the
  270. coverage plugin, or in any other case where module reloading may
  271. produce undesirable side-effects. [NOSE_WITH_ISOLATION]
  272. -d, --detailed-errors, --failure-detail
  273. Add detail to error output by attempting to evaluate failed asserts
  274. [NOSE_DETAILED_ERRORS]
  275. --with-profile
  276. Enable plugin Profile: Use this plugin to run tests using the
  277. hotshot profiler. [NOSE_WITH_PROFILE]
  278. --profile-sort=SORT
  279. Set sort order for profiler output
  280. --profile-stats-file=FILE
  281. Profiler stats file; default is a new temp file on each run
  282. --profile-restrict=RESTRICT
  283. Restrict profiler output. See help for pstats.Stats for details
  284. --no-skip
  285. Disable special handling of SkipTest exceptions.
  286. --with-id
  287. Enable plugin TestId: Activate to add a test id (like #1) to each
  288. test name output. Activate with --failed to rerun failing tests
  289. only. [NOSE_WITH_ID]
  290. --id-file=FILE
  291. Store test ids found in test runs in this file. Default is the file
  292. .noseids in the working directory.
  293. --failed
  294. Run the tests that failed in the last test run.
  295. --processes=NUM
  296. Spread test run among this many processes. Set a number equal to
  297. the number of processors or cores in your machine for best results.
  298. [NOSE_PROCESSES]
  299. --process-timeout=SECONDS
  300. Set timeout for return of results from each test runner process.
  301. [NOSE_PROCESS_TIMEOUT]
  302. --process-restartworker
  303. If set, will restart each worker process once their tests are done,
  304. this helps control memory leaks from killing the system.
  305. [NOSE_PROCESS_RESTARTWORKER]
  306. --with-xunit
  307. Enable plugin Xunit: This plugin provides test results in the
  308. standard XUnit XML format. [NOSE_WITH_XUNIT]
  309. --xunit-file=FILE
  310. Path to xml file to store the xunit report in. Default is
  311. nosetests.xml in the working directory [NOSE_XUNIT_FILE]
  312. --all-modules
  313. Enable plugin AllModules: Collect tests from all python modules.
  314. [NOSE_ALL_MODULES]
  315. --collect-only
  316. Enable collect-only: Collect and output test names only, don't run
  317. any tests. [COLLECT_ONLY]