          cls._module.urlpatterns = cls.urlpatterns
  
          cls._override.enable()
          super().setUpClass()
  
      if django.VERSION < (4, 0):
          @classmethod
          def tearDownClass(cls):
              super().tearDownClass()
 
</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() </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
        if django.VERSION > (4, 0):
            cls.addClassCleanup(cls._override.disable)
            cls.addClassCleanup(cleanup_url_patterns, cls)

          cls._module.urlpatterns = cls.urlpatterns
  
          cls._override.enable()
        if django.VERSION > (4, 0):
            cls.addClassCleanup(cls._override.disable)
            cls.addClassCleanup(cleanup_url_patterns, cls)

          super().setUpClass()
  
      if django.VERSION < (4, 0):
          @classmethod
          def tearDownClass(cls):
              super().tearDownClass()
keep keep add keep 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. 
rest_framework/test.py