From 679212a47ac3e22a6fbb6ee3cd4c09f29aae8b5d Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 3 Oct 2023 09:25:48 +0200 Subject: Refs #34657 -- Made msg_prefix handling in assertURLEqual()/assertInHTML consistent with other assertions. Co-authored-by: Chinmoy Chakraborty --- tests/test_utils/tests.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'tests/test_utils') 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("Hello", "

Test

") + def test_msg_prefix(self): + msg = "False is not true : Prefix: Couldn't find 'Hello' in response" + with self.assertRaisesMessage(AssertionError, msg): + self.assertInHTML( + "Hello", + '', + msg_prefix="Prefix", + ) + + def test_count_msg_prefix(self): + msg = ( + "2 != 1 : Prefix: Found 2 instances of 'Hello' in response " + "(expected 1)" + ) + with self.assertRaisesMessage(AssertionError, msg): + self.assertInHTML( + "Hello", + "HelloHello", + 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", ) -- cgit v1.3