  from io import BytesIO
  
  from django.contrib.auth.models import User
  from django.shortcuts import redirect
  from django.test import TestCase, override_settings
  from django.urls import path
  
 
</s> remove     @classmethod
    def tearDownClass(cls):
        assert urlpatterns is cls.urlpatterns
        super().tearDownClass()
        assert urlpatterns is not cls.urlpatterns
 </s> add         if django.VERSION > (4, 0):
            cls.addClassCleanup(
                check_urlpatterns,
                cls
            )

    if django.VERSION < (4, 0):
        @classmethod
        def tearDownClass(cls):
            assert urlpatterns is cls.urlpatterns
            super().tearDownClass()
            assert urlpatterns is not cls.urlpatterns </s> remove         if hasattr(cls, '_module_urlpatterns'):
            cls._module.urlpatterns = cls._module_urlpatterns
        else:
            del cls._module.urlpatterns
 </s> add             if hasattr(cls, '_module_urlpatterns'):
                cls._module.urlpatterns = cls._module_urlpatterns
            else:
                del cls._module.urlpatterns </s> remove     @classmethod
    def tearDownClass(cls):
        super().tearDownClass()
        cls._override.disable()
 </s> add     if django.VERSION < (4, 0):
        @classmethod
        def tearDownClass(cls):
            super().tearDownClass()
            cls._override.disable()
import django
  from io import BytesIO
  
import django
  from django.contrib.auth.models import User
  from django.shortcuts import redirect
  from django.test import TestCase, override_settings
  from django.urls import path
  
keep add keep keep keep keep keep
 Adjusted URLPatternsTestCase to use addClassCleanup() from Django 4.0.

Refs https://github.com/django/django/commit/faba5b702a9c5bb9452a543100928bcb5f66ebcf.

addClassCleanup() is available from Python 3.8, which is the minimum supported
Python from Django 4.0. 
tests/test_testing.py