diff options
Diffstat (limited to 'Doc/library/unittest.rst')
| -rw-r--r-- | Doc/library/unittest.rst | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst index 283d2fd..9abf727 100644 --- a/Doc/library/unittest.rst +++ b/Doc/library/unittest.rst @@ -591,7 +591,7 @@ This section describes in depth the API of :mod:`unittest`. Test cases ~~~~~~~~~~ -.. class:: TestCase([methodName]) +.. class:: TestCase(methodName='runTest') Instances of the :class:`TestCase` class represent the smallest testable units in the :mod:`unittest` universe. This class is intended to be used as a base @@ -642,7 +642,7 @@ Test cases the outcome of the test method. The default implementation does nothing. - .. method:: run([result]) + .. method:: run(result=None) Run the test, collecting the result into the test result object passed as *result*. If *result* is omitted or :const:`None`, a temporary result @@ -669,9 +669,9 @@ Test cases failures. - .. method:: assertTrue(expr[, msg]) - assert_(expr[, msg]) - failUnless(expr[, msg]) + .. method:: assertTrue(expr, msg=None) + assert_(expr, msg=None) + failUnless(expr, msg=None) Signal a test failure if *expr* is false; the explanation for the failure will be *msg* if given, otherwise it will be :const:`None`. @@ -680,8 +680,8 @@ Test cases :meth:`failUnless`. - .. method:: assertEqual(first, second[, msg]) - failUnlessEqual(first, second[, msg]) + .. method:: assertEqual(first, second, msg=None) + failUnlessEqual(first, second, msg=None) Test that *first* and *second* are equal. If the values do not compare equal, the test will fail with the explanation given by *msg*, or @@ -702,8 +702,8 @@ Test cases :meth:`failUnlessEqual`. - .. method:: assertNotEqual(first, second[, msg]) - failIfEqual(first, second[, msg]) + .. method:: assertNotEqual(first, second, msg=None) + failIfEqual(first, second, msg=None) Test that *first* and *second* are not equal. If the values do compare equal, the test will fail with the explanation given by *msg*, or @@ -716,8 +716,8 @@ Test cases :meth:`failIfEqual`. - .. method:: assertAlmostEqual(first, second[, places[, msg]]) - failUnlessAlmostEqual(first, second[, places[, msg]]) + .. method:: assertAlmostEqual(first, second, *, places=7, msg=None) + failUnlessAlmostEqual(first, second, *, places=7, msg=None) Test that *first* and *second* are approximately equal by computing the difference, rounding to the given number of decimal *places* (default 7), @@ -732,8 +732,8 @@ Test cases :meth:`failUnlessAlmostEqual`. - .. method:: assertNotAlmostEqual(first, second[, places[, msg]]) - failIfAlmostEqual(first, second[, places[, msg]]) + .. method:: assertNotAlmostEqual(first, second, *, places=7, msg=None) + failIfAlmostEqual(first, second, *, places=7, msg=None) Test that *first* and *second* are not approximately equal by computing the difference, rounding to the given number of decimal *places* (default @@ -774,7 +774,7 @@ Test cases .. versionadded:: 3.1 - .. method:: assertRegexpMatches(text, regexp[, msg=None]): + .. method:: assertRegexpMatches(text, regexp, msg=None): Verifies that a *regexp* search matches *text*. Fails with an error message including the pattern and the *text*. *regexp* may be @@ -867,8 +867,10 @@ Test cases .. versionadded:: 3.1 - .. method:: assertRaises(exception[, callable, ...]) - failUnlessRaises(exception[, callable, ...]) + .. method:: assertRaises(exception, callable, *args, **kwds) + failUnlessRaises(exception, callable, *args, **kwds) + assertRaises(exception) + failUnlessRaises(exception) Test that an exception is raised when *callable* is called with any positional or keyword arguments that are also passed to @@ -877,8 +879,8 @@ Test cases To catch any of a group of exceptions, a tuple containing the exception classes may be passed as *exception*. - If *callable* is omitted or None, returns a context manager so that the - code under test can be written inline rather than as a function:: + If only the *exception* argument is given, returns a context manager so + that the code under test can be written inline rather than as a function:: with self.failUnlessRaises(some_error_class): do_something() @@ -908,14 +910,14 @@ Test cases .. versionadded:: 3.1 - .. method:: assertIsNone(expr[, msg]) + .. method:: assertIsNone(expr, msg=None) This signals a test failure if *expr* is not None. .. versionadded:: 3.1 - .. method:: assertIsNotNone(expr[, msg]) + .. method:: assertIsNotNone(expr, msg=None) The inverse of the :meth:`assertIsNone` method. This signals a test failure if *expr* is None. @@ -923,7 +925,7 @@ Test cases .. versionadded:: 3.1 - .. method:: assertIs(expr1, expr2[, msg]) + .. method:: assertIs(expr1, expr2, msg=None) This signals a test failure if *expr1* and *expr2* don't evaluate to the same object. @@ -931,7 +933,7 @@ Test cases .. versionadded:: 3.1 - .. method:: assertIsNot(expr1, expr2[, msg]) + .. method:: assertIsNot(expr1, expr2, msg=None) The inverse of the :meth:`assertIs` method. This signals a test failure if *expr1* and *expr2* evaluate to the same @@ -940,8 +942,8 @@ Test cases .. versionadded:: 3.1 - .. method:: assertFalse(expr[, msg]) - failIf(expr[, msg]) + .. method:: assertFalse(expr, msg=None) + failIf(expr, msg=None) The inverse of the :meth:`assertTrue` method is the :meth:`assertFalse` method. This signals a test failure if *expr* is true, with *msg* or :const:`None` @@ -951,7 +953,7 @@ Test cases :meth:`failIf`. - .. method:: fail([msg]) + .. method:: fail(msg=None) Signals a test failure unconditionally, with *msg* or :const:`None` for the error message. @@ -1042,7 +1044,7 @@ Test cases .. versionadded:: 3.1 - .. method:: addCleanup(function[, *args[, **kwargs]]) + .. method:: addCleanup(function, *args, **kwargs) Add a function to be called after :meth:`tearDown` to cleanup resources used during the test. Functions will be called in reverse order to the @@ -1072,7 +1074,7 @@ Test cases .. versionadded:: 2.7 -.. class:: FunctionTestCase(testFunc[, setUp[, tearDown[, description]]]) +.. class:: FunctionTestCase(testFunc, setUp=None, tearDown=None, description=None) This class implements the portion of the :class:`TestCase` interface which allows the test runner to drive the test, but does not provide the methods @@ -1086,7 +1088,7 @@ Test cases Grouping tests ~~~~~~~~~~~~~~ -.. class:: TestSuite([tests]) +.. class:: TestSuite(tests=()) This class represents an aggregation of individual tests cases and test suites. The class presents the interface needed by the test runner to allow it to be run @@ -1200,7 +1202,7 @@ Loading and running tests Support for ``load_tests`` added. - .. method:: loadTestsFromName(name[, module]) + .. method:: loadTestsFromName(name, module=None) Return a suite of all tests cases given a string specifier. @@ -1225,7 +1227,7 @@ Loading and running tests The method optionally resolves *name* relative to the given *module*. - .. method:: loadTestsFromNames(names[, module]) + .. method:: loadTestsFromNames(names, module=None) Similar to :meth:`loadTestsFromName`, but takes a sequence of names rather than a single name. The return value is a test suite which supports all @@ -1467,7 +1469,7 @@ Loading and running tests instead of repeatedly creating new instances. -.. class:: TextTestRunner([stream[, descriptions[, verbosity]]]) +.. class:: TextTestRunner(stream=sys.stderr, descriptions=True, verbosity=1) A basic test runner implementation which prints results on standard error. It has a few configurable parameters, but is essentially very simple. Graphical @@ -1480,7 +1482,7 @@ Loading and running tests subclasses to provide a custom ``TestResult``. -.. function:: main([module[, defaultTest[, argv[, testRunner[, testLoader[, exit, [verbosity]]]]]]]) +.. function:: main(module='__main__', defaultTest=None, argv=None, testRunner=None, testLoader=unittest.loader.defaultTestLoader, exit=True, verbosity=1) A command-line program that runs a set of tests; this is primarily for making test modules conveniently executable. The simplest use for this function is to |
