Improving docstrings in unittest.TestCase

This commit is contained in:
Michael Foord 2010-02-05 22:55:09 +00:00
parent fb0844bcc8
commit d0edec38ce
1 changed files with 15 additions and 5 deletions

View File

@ -218,10 +218,6 @@ class TestCase(object):
"""Returns both the test method name and first line of its docstring. """Returns both the test method name and first line of its docstring.
If no docstring is given, only returns the method name. 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) desc = str(self)
doc_first_line = None doc_first_line = None
@ -384,8 +380,17 @@ class TestCase(object):
If called with callableObj omitted or None, will return a If called with callableObj omitted or None, will return a
context object used like this:: context object used like this::
with self.assertRaises(some_error_class): with self.assertRaises(SomeException):
do_something() do_something()
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) context = _AssertRaisesContext(excClass, self)
if callableObj is None: if callableObj is None:
@ -733,6 +738,11 @@ class TestCase(object):
Raises with an error message listing which elements of expected_seq Raises with an error message listing which elements of expected_seq
are missing from actual_seq and vice versa if any. 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.
""" """
try: try:
expected = set(expected_seq) expected = set(expected_seq)