Anonymous avatar Anonymous committed 3dd921a

Improving docstrings in unittest.TestCase

Comments (0)

Files changed (1)


         """Returns both the test method name and first line of its docstring.
         If no docstring is given, only returns the method name.
-        This method overrides unittest.TestCase.shortDescription(), which
-        only returns the first line of the docstring, obscuring the name
-        of the test upon failure.
         desc = str(self)
         doc_first_line = None
            If called with callableObj omitted or None, will return a
            context object used like this::
-                with self.assertRaises(some_error_class):
+                with self.assertRaises(SomeException):
+           The context manager keeps a reference to the exception as
+           the exc_value attribute. This allows you to inspect the
+           exception after the assertion::
+               with self.assertRaises(SomeException) as cm:
+                   do_something()
+               the_exception = cm.exc_value
+               self.assertEquals(the_exception.error_code, 3)
         context = _AssertRaisesContext(excClass, self)
         if callableObj is None:
         Raises with an error message listing which elements of expected_seq
         are missing from actual_seq and vice versa if any.
+        Duplicate elements are ignored when comparing *expected_seq* and
+        *actual_seq*. It is the equivalent of ``assertEqual(set(expected),
+        set(actual))`` but it works with sequences of unhashable objects as
+        well.
             expected = set(expected_seq)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.