From 0e84e70bc8e0140a1e22f25bc6cb852d95a79949 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 29 Feb 2024 08:22:03 +0100 Subject: [PATCH] Refs #35090 -- Fixed urlpatterns.tests.SimplifiedURLTests when run in reverse. --- tests/urlpatterns/tests.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/urlpatterns/tests.py b/tests/urlpatterns/tests.py index 37109c9a1193..370e8695606c 100644 --- a/tests/urlpatterns/tests.py +++ b/tests/urlpatterns/tests.py @@ -13,7 +13,7 @@ resolve, reverse, ) -from django.urls.converters import IntConverter +from django.urls.converters import REGISTERED_CONVERTERS, IntConverter from django.utils.deprecation import RemovedInDjango60Warning from django.views import View @@ -211,8 +211,11 @@ def test_warning_override_default_converter(self): "Converter 'int' is already registered. Support for overriding registered " "converters is deprecated and will be removed in Django 6.0." ) - with self.assertWarnsMessage(RemovedInDjango60Warning, msg): - register_converter(IntConverter, "int") + try: + with self.assertWarnsMessage(RemovedInDjango60Warning, msg): + register_converter(IntConverter, "int") + finally: + REGISTERED_CONVERTERS.pop("int", None) def test_warning_override_converter(self): # RemovedInDjango60Warning: when the deprecation ends, replace with @@ -222,8 +225,12 @@ def test_warning_override_converter(self): "Converter 'base64' is already registered. Support for overriding " "registered converters is deprecated and will be removed in Django 6.0." ) - with self.assertWarnsMessage(RemovedInDjango60Warning, msg): - register_converter(Base64Converter, "base64") + try: + with self.assertWarnsMessage(RemovedInDjango60Warning, msg): + register_converter(Base64Converter, "base64") + register_converter(Base64Converter, "base64") + finally: + REGISTERED_CONVERTERS.pop("base64", None) def test_invalid_view(self): msg = "view must be a callable or a list/tuple in the case of include()."