summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/test/testcases.py4
-rw-r--r--docs/releases/5.1.txt4
-rw-r--r--tests/test_utils/tests.py24
3 files changed, 31 insertions, 1 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 391b5e99cc..bdb64b3a15 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -463,6 +463,8 @@ class SimpleTestCase(unittest.TestCase):
(scheme, netloc, path, params, urlencode(query_parts), fragment)
)
+ if msg_prefix:
+ msg_prefix += ": "
self.assertEqual(
normalize(url1),
normalize(url2),
@@ -880,6 +882,8 @@ class SimpleTestCase(unittest.TestCase):
self, haystack, None, "Second argument is not valid HTML:"
)
real_count = parsed_haystack.count(parsed_needle)
+ if msg_prefix:
+ msg_prefix += ": "
if count is not None:
self.assertEqual(
real_count,
diff --git a/docs/releases/5.1.txt b/docs/releases/5.1.txt
index bd70a2c7ac..a8f0c32f9b 100644
--- a/docs/releases/5.1.txt
+++ b/docs/releases/5.1.txt
@@ -254,6 +254,10 @@ Miscellaneous
* In order to improve accessibility, the admin's changelist filter is now
rendered in a ``<nav>`` tag instead of a ``<div>``.
+* :meth:`.SimpleTestCase.assertURLEqual` and
+ :meth:`~django.test.SimpleTestCase.assertInHTML` now add ``": "`` to the
+ ``msg_prefix``. This is consistent with the behavior of other assertions.
+
.. _deprecated-features-5.1:
Features deprecated in 5.1
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index 3ee78a60a3..95526f768f 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -989,6 +989,28 @@ class InHTMLTests(SimpleTestCase):
with self.assertRaisesMessage(AssertionError, msg):
self.assertInHTML("<b>Hello</b>", "<p>Test</p>")
+ def test_msg_prefix(self):
+ msg = "False is not true : Prefix: Couldn't find '<b>Hello</b>' in response"
+ with self.assertRaisesMessage(AssertionError, msg):
+ self.assertInHTML(
+ "<b>Hello</b>",
+ '<input type="text" name="Hello" />',
+ msg_prefix="Prefix",
+ )
+
+ def test_count_msg_prefix(self):
+ msg = (
+ "2 != 1 : Prefix: Found 2 instances of '<b>Hello</b>' in response "
+ "(expected 1)"
+ )
+ with self.assertRaisesMessage(AssertionError, msg):
+ self.assertInHTML(
+ "<b>Hello</b>",
+ "<b>Hello</b><b>Hello</b>",
+ count=1,
+ msg_prefix="Prefix",
+ )
+
class JSONEqualTests(SimpleTestCase):
def test_simple_equal(self):
@@ -1268,7 +1290,7 @@ class AssertURLEqualTests(SimpleTestCase):
self.assertURLEqual(
"http://example.com/?x=1&x=2",
"https://example.com/?x=2&x=1",
- msg_prefix="Prefix: ",
+ msg_prefix="Prefix",
)