diff --git a/django/test/testcases.py b/django/test/testcases.py index 3dd14a08c0..991165c04d 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -393,6 +393,7 @@ class SimpleTestCase(unittest.TestCase): """ def normalize(url): """Sort the URL's query string parameters.""" + url = str(url) # Coerce reverse_lazy() URLs. scheme, netloc, path, params, query, fragment = urlparse(url) query_parts = sorted(parse_qsl(query)) return urlunparse((scheme, netloc, path, params, urlencode(query_parts), fragment)) diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index 3a315e7c10..a1a113a26e 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -22,7 +22,7 @@ from django.test.utils import ( CaptureQueriesContext, TestContextDecorator, isolate_apps, override_settings, setup_test_environment, ) -from django.urls import NoReverseMatch, path, reverse +from django.urls import NoReverseMatch, path, reverse, reverse_lazy from .models import Car, Person, PossessedCar from .views import empty_response @@ -961,6 +961,7 @@ class AssertFieldOutputTests(SimpleTestCase): self.assertFieldOutput(MyCustomField, {}, {}, empty_value=None) +@override_settings(ROOT_URLCONF='test_utils.urls') class AssertURLEqualTests(SimpleTestCase): def test_equal(self): valid_tests = ( @@ -971,6 +972,7 @@ class AssertURLEqualTests(SimpleTestCase): ('http://example.com/?x=1&y=2&a=1&a=2', 'http://example.com/?a=1&a=2&y=2&x=1'), ('/path/to/?x=1&y=2&z=3', '/path/to/?z=3&y=2&x=1'), ('?x=1&y=2&z=3', '?z=3&y=2&x=1'), + ('/test_utils/no_template_used/', reverse_lazy('no_template_used')), ) for url1, url2 in valid_tests: with self.subTest(url=url1): diff --git a/tests/test_utils/urls.py b/tests/test_utils/urls.py index 5cfab5d831..6b060dff95 100644 --- a/tests/test_utils/urls.py +++ b/tests/test_utils/urls.py @@ -4,5 +4,5 @@ from . import views urlpatterns = [ path('test_utils/get_person//', views.get_person), - path('test_utils/no_template_used/', views.no_template_used), + path('test_utils/no_template_used/', views.no_template_used, name='no_template_used'), ]