diff options
| author | Tim Graham <timograham@gmail.com> | 2015-05-17 16:25:36 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-05-18 10:16:14 -0400 |
| commit | 02a4bf7105fd9fe48a24478bb5740a14960e5897 (patch) | |
| tree | b7fd7e18199bf2c39e751b1abddaa47e8d2abacf /docs | |
| parent | 3c0e03ef42eda07adefaae0656613803a74e8699 (diff) | |
[1.8.x] Added docs for assertRaisesMessage as context manager.
Backport of a0175724b086127a4e13612042961d3ba88d6bd9 from master
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/topics/testing/tools.txt | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt index 681f1cf360..d0b63e79ab 100644 --- a/docs/topics/testing/tools.txt +++ b/docs/topics/testing/tools.txt @@ -1326,13 +1326,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 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 - ``expected_exception`` exception and that such exception has an - ``expected_message`` representation. Any other outcome is reported as a - failure. Similar to unittest's :meth:`~unittest.TestCase.assertRaisesRegex` - with the difference that ``expected_message`` isn't a regular expression. + Asserts that execution of ``callable`` raises ``expected_exception`` and + that the exception has an ``expected_message`` representation. Any other + outcome is reported as a failure. Similar to unittest's + :meth:`~unittest.TestCase.assertRaisesRegex` with the difference that + ``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='') |
