From b3f96b5f7302a032a704541fe3a38d285c9e2f30 Mon Sep 17 00:00:00 2001 From: Dmitry Dygalo Date: Wed, 20 Jul 2016 16:12:13 +0200 Subject: [PATCH] [1.10.x] Fixed #26922 -- Fixed SimpleTestCase.assertHTMLEqual() crash on Python 3.5+. Backport of d7a097265b1842843a73ce0da36ef98bacac8a3e from master --- django/test/testcases.py | 2 +- tests/test_utils/tests.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/django/test/testcases.py b/django/test/testcases.py index 26a1325532..841a9faf96 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -66,7 +66,7 @@ def assert_and_parse_html(self, html, user_msg, msg): try: dom = parse_html(html) except HTMLParseError as e: - standardMsg = '%s\n%s' % (msg, e.msg) + standardMsg = '%s\n%s' % (msg, e) self.fail(self._formatMessage(user_msg, standardMsg)) return dom diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index fd552ad9c2..395884fedf 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals +import sys import unittest import warnings @@ -629,6 +630,15 @@ class HTMLEqualTests(SimpleTestCase): self.assertHTMLEqual('

', '') with self.assertRaises(AssertionError): self.assertHTMLEqual('', '

') + error_msg = ( + "First argument is not valid HTML:\n" + "('Unexpected end tag `div` (Line 1, Column 6)', (1, 6))" + ) if sys.version_info >= (3, 5) else ( + "First argument is not valid HTML:\n" + "Unexpected end tag `div` (Line 1, Column 6), at line 1, column 7" + ) + with self.assertRaisesMessage(AssertionError, error_msg): + self.assertHTMLEqual('< div>', '

') with self.assertRaises(HTMLParseError): parse_html('

')