Doctests: run doctests with nose¶
│ │ │Use the Doctest plugin with --with-doctest
or the NOSE_WITH_DOCTEST
│ │ │ -environment variable to enable collection and execution of doctests
. Because doctests are usually included in the tested package
│ │ │ +environment variable to enable collection and execution of doctests
. Because doctests are usually included in the tested package
│ │ │ (instead of being grouped into packages or modules of their own), nose only
│ │ │ looks for them in the non-test packages it discovers in the working directory.
Doctests may also be placed into files other than python modules, in which
│ │ │ case they can be collected and executed by using the --doctest-extension
│ │ │ switch or NOSE_DOCTEST_EXTENSION environment variable to indicate which file
│ │ │ extension(s) to load.
When loading doctests from non-module files, use the --doctest-fixtures
│ │ ├── ./usr/share/doc/python-nose-doc/html/plugins/interface.html
│ │ │ @@ -261,15 +261,15 @@
│ │ │ addFailure
(test, err)¶
│ │ │
Called when a test fails. DO NOT return a value unless you │ │ │ want to stop other plugins from seeing that the test has failed.
│ │ │-
│ │ │
- Parameters │ │ │
-
│ │ │
test (
nose.case.Test
) – the test case
│ │ │ -err (sys.exc_info() tuple) – 3-tuple
│ │ │ +err (sys.exc_info() tuple) – 3-tuple
│ │ │
│ │ │
-
│ │ │
-
│ │ │ @@ -650,29 +650,29 @@
│ │ │
loadTestsFromTestCase
(cls)¶
│ │ │ Return tests in this test case class. Return None if you are │ │ │ not able to load any tests, or an iterable if you are. May be a │ │ │ generator.
│ │ │-
│ │ │
- Parameters │ │ │
cls – The test case class. Must be subclass of │ │ │ -
│ │ │ +unittest.TestCase
.unittest.TestCase
. │ │ │
│ │ │
-
│ │ │
-
│ │ │
loadTestsFromTestClass
(cls)¶
│ │ │ Return tests in this test class. Class will not be a │ │ │ unittest.TestCase subclass. Return None if you are not able to │ │ │ load any tests, an iterable if you are. May be a generator.
│ │ │-
│ │ │
- Parameters │ │ │
cls – The test case class. Must be not be subclass of │ │ │ -
│ │ │ +unittest.TestCase
.unittest.TestCase
. │ │ │
│ │ │
-
│ │ │
-
│ │ │
makeTest
(obj, parent)¶
│ │ ├── ./usr/share/doc/python-nose-doc/html/testing.html
│ │ │ @@ -47,17 +47,17 @@
│ │ │
│ │ │
│ │ │
│ │ │
Testing with nose¶
│ │ │Writing tests is easier¶
│ │ │ -nose collects tests from unittest.TestCase
subclasses, of course. But
│ │ │ +
nose collects tests from unittest.TestCase
subclasses, of course. But
│ │ │ you can also write simple test functions, as well as test classes that are
│ │ │ -not subclasses of unittest.TestCase
. nose also supplies a number of
│ │ │ +not subclasses of unittest.TestCase
. nose also supplies a number of
│ │ │ helpful functions for writing timed tests, testing for exceptions, and other
│ │ │ common use cases. See Writing tests and Testing tools for more.
Running tests is easier¶
│ │ │nose collects tests automatically, as long as you follow some simple │ │ │ guidelines for organizing your library and test code. There’s no need │ │ ├── ./usr/share/doc/python-nose-doc/html/writing_tests.html │ │ │ @@ -47,20 +47,20 @@ │ │ │
Writing tests¶
│ │ │As with py.test, nose tests need not be subclasses of
│ │ │ -unittest.TestCase
. Any function or class that matches the configured
│ │ │ +unittest.TestCase
. Any function or class that matches the configured
│ │ │ testMatch regular expression ((?:^|[\\b_\\.-])[Tt]est
by default – that
│ │ │ is, has test or Test at a word boundary or following a - or _) and lives in a
│ │ │ module that also matches that expression will be run as a test. For the sake
│ │ │ of compatibility with legacy unittest test cases, nose will also load tests
│ │ │ -from unittest.TestCase
subclasses just like unittest does. Like
│ │ │ +from unittest.TestCase
subclasses just like unittest does. Like
│ │ │ py.test, nose runs functional tests in the order in which they appear in the
│ │ │ module file. TestCase-derived tests and other test classes are run in
│ │ │ alphabetical order.
Fixtures¶
│ │ │nose supports fixtures (setup and teardown methods) at the package, │ │ │ module, class, and test level. As with py.test or unittest fixtures, │ │ │ @@ -90,18 +90,18 @@ │ │ │ method setup, setup_module, setUp or setUpModule for setup, │ │ │ teardown, teardown_module, or tearDownModule for teardown. Execution │ │ │ of tests in a test module begins after all tests are collected.
│ │ │Test classes¶
│ │ │A test class is a class defined in a test module that matches testMatch or is
│ │ │ -a subclass of unittest.TestCase
. All test classes are run the same
│ │ │ +a subclass of unittest.TestCase
. All test classes are run the same
│ │ │ way: Methods in the class that match testMatch are discovered, and a test
│ │ │ case is constructed to run each method with a fresh instance of the test
│ │ │ -class. Like unittest.TestCase
subclasses, other test classes can
│ │ │ +class. Like unittest.TestCase
subclasses, other test classes can
│ │ │ define setUp and tearDown methods that will be run before and after each test
│ │ │ method. Test classes that do not descend from unittest.TestCase may also
│ │ │ include generator methods and class-level fixtures. Class-level setup fixtures
│ │ │ may be named setup_class, setupClass, setUpClass, setupAll or
│ │ │ setUpAll; teardown fixtures may be named teardown_class, teardownClass,
│ │ │ tearDownClass, teardownAll or tearDownAll. Class-level setup and teardown
│ │ │ fixtures must be class methods.