Added docs for assertRaisesMessage as context manager.

This commit is contained in:
Tim Graham 2015-05-17 16:25:36 -04:00
parent 7d97c5745e
commit a0175724b0
1 changed files with 14 additions and 6 deletions

View File

@ -1284,13 +1284,21 @@ message generated by the assertion. This allows you to provide additional
details that may help you to identify the location and cause of an failure in details that may help you to identify the location and cause of an failure in
your test suite. your test suite.
.. method:: SimpleTestCase.assertRaisesMessage(expected_exception, expected_message, callable_obj=None, *args, **kwargs) .. method:: SimpleTestCase.assertRaisesMessage(expected_exception, expected_message, callable, *args, **kwargs)
SimpleTestCase.assertRaisesMessage(expected_exception, expected_message)
Asserts that execution of callable ``callable_obj`` raised the Asserts that execution of ``callable`` raises ``expected_exception`` and
``expected_exception`` exception and that such exception has an that the exception has an ``expected_message`` representation. Any other
``expected_message`` representation. Any other outcome is reported as a outcome is reported as a failure. Similar to unittest's
failure. Similar to unittest's :meth:`~unittest.TestCase.assertRaisesRegex` :meth:`~unittest.TestCase.assertRaisesRegex` with the difference that
with the difference that ``expected_message`` isn't a regular expression. ``expected_message`` isn't a regular expression.
If only the ``expected_exception`` and ``expected_message`` parameters are
given, returns a context manager so that the code being tested can be
written inline rather than as a function::
with self.assertRaisesMessage(ValueError, 'invalid literal for int()'):
int('a')
.. method:: SimpleTestCase.assertFieldOutput(fieldclass, valid, invalid, field_args=None, field_kwargs=None, empty_value='') .. method:: SimpleTestCase.assertFieldOutput(fieldclass, valid, invalid, field_args=None, field_kwargs=None, empty_value='')