usage.txt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. nose collects tests automatically from python source files,
  2. directories and packages found in its working directory (which
  3. defaults to the current working directory). Any python source file,
  4. directory or package that matches the testMatch regular expression
  5. (by default: `(?:^|[\b_\.-])[Tt]est)` will be collected as a test (or
  6. source for collection of tests). In addition, all other packages
  7. found in the working directory will be examined for python source files
  8. or directories that match testMatch. Package discovery descends all
  9. the way down the tree, so package.tests and package.sub.tests and
  10. package.sub.sub2.tests will all be collected.
  11. Within a test directory or package, any python source file matching
  12. testMatch will be examined for test cases. Within a test module,
  13. functions and classes whose names match testMatch and TestCase
  14. subclasses with any name will be loaded and executed as tests. Tests
  15. may use the assert keyword or raise AssertionErrors to indicate test
  16. failure. TestCase subclasses may do the same or use the various
  17. TestCase methods available.
  18. **It is important to note that the default behavior of nose is to
  19. not include tests from files which are executable.** To include
  20. tests from such files, remove their executable bit or use
  21. the --exe flag (see 'Options' section below).
  22. Selecting Tests
  23. ---------------
  24. To specify which tests to run, pass test names on the command line:
  25. %prog only_test_this.py
  26. Test names specified may be file or module names, and may optionally
  27. indicate the test case to run by separating the module or file name
  28. from the test case name with a colon. Filenames may be relative or
  29. absolute. Examples:
  30. %prog test.module
  31. %prog another.test:TestCase.test_method
  32. %prog a.test:TestCase
  33. %prog /path/to/test/file.py:test_function
  34. You may also change the working directory where nose looks for tests
  35. by using the -w switch:
  36. %prog -w /path/to/tests
  37. Note, however, that support for multiple -w arguments is now deprecated
  38. and will be removed in a future release. As of nose 0.10, you can get
  39. the same behavior by specifying the target directories *without*
  40. the -w switch:
  41. %prog /path/to/tests /another/path/to/tests
  42. Further customization of test selection and loading is possible
  43. through the use of plugins.
  44. Test result output is identical to that of unittest, except for
  45. the additional features (error classes, and plugin-supplied
  46. features such as output capture and assert introspection) detailed
  47. in the options below.
  48. Configuration
  49. -------------
  50. In addition to passing command-line options, you may also put
  51. configuration options in your project's *setup.cfg* file, or a .noserc
  52. or nose.cfg file in your home directory. In any of these standard
  53. ini-style config files, you put your nosetests configuration in a
  54. ``[nosetests]`` section. Options are the same as on the command line,
  55. with the -- prefix removed. For options that are simple switches, you
  56. must supply a value:
  57. [nosetests]
  58. verbosity=3
  59. with-doctest=1
  60. All configuration files that are found will be loaded and their
  61. options combined. You can override the standard config file loading
  62. with the ``-c`` option.
  63. Using Plugins
  64. -------------
  65. There are numerous nose plugins available via easy_install and
  66. elsewhere. To use a plugin, just install it. The plugin will add
  67. command line options to nosetests. To verify that the plugin is installed,
  68. run:
  69. nosetests --plugins
  70. You can add -v or -vv to that command to show more information
  71. about each plugin.
  72. If you are running nose.main() or nose.run() from a script, you
  73. can specify a list of plugins to use by passing a list of plugins
  74. with the plugins keyword argument.
  75. 0.9 plugins
  76. -----------
  77. nose 1.0 can use SOME plugins that were written for nose 0.9. The
  78. default plugin manager inserts a compatibility wrapper around 0.9
  79. plugins that adapts the changed plugin api calls. However, plugins
  80. that access nose internals are likely to fail, especially if they
  81. attempt to access test case or test suite classes. For example,
  82. plugins that try to determine if a test passed to startTest is an
  83. individual test or a suite will fail, partly because suites are no
  84. longer passed to startTest and partly because it's likely that the
  85. plugin is trying to find out if the test is an instance of a class
  86. that no longer exists.
  87. 0.10 and 0.11 plugins
  88. ---------------------
  89. All plugins written for nose 0.10 and 0.11 should work with nose 1.0.