Kaydet (Commit) 77f50c9c authored tarafından Tim Graham's avatar Tim Graham

Fixed #25948 -- Added guidelines for SimpleTestCase.assertRaisesMessage() usage.

üst 0224f1cb
...@@ -45,6 +45,12 @@ Python style ...@@ -45,6 +45,12 @@ Python style
""" """
... ...
* In tests, use :meth:`~django.test.SimpleTestCase.assertRaisesMessage` instead
of :meth:`~unittest.TestCase.assertRaises` so you can check the exception
message. Use :meth:`~unittest.TestCase.assertRaisesRegex`
(``six.assertRaisesRegex()`` as long as we support Python 2) only if you need
to use regular expression matching.
Imports Imports
------- -------
......
...@@ -1345,9 +1345,9 @@ your test suite. ...@@ -1345,9 +1345,9 @@ your test suite.
Asserts that execution of ``callable`` raises ``expected_exception`` and Asserts that execution of ``callable`` raises ``expected_exception`` and
that ``expected_message`` is found in the exception's message. Any other that ``expected_message`` is found in the exception's message. Any other
outcome is reported as a failure. Similar to unittest's outcome is reported as a failure. It's a simpler version of
:meth:`~unittest.TestCase.assertRaisesRegex` with the difference that :meth:`unittest.TestCase.assertRaisesRegex` with the difference that
``expected_message`` isn't a regular expression. ``expected_message`` isn't treated as a regular expression.
If only the ``expected_exception`` and ``expected_message`` parameters are If only the ``expected_exception`` and ``expected_message`` parameters are
given, returns a context manager so that the code being tested can be given, returns a context manager so that the code being tested can be
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment