Repository: encode/django-rest-framework

Issue:
url() is deprecated in Django 3.1 
CI is raising warnings as `url()` is deprecated in the upcoming release of Django.

https://travis-ci.org/github/encode/django-rest-framework/jobs/707134589




Discussion:
check https://github.com/encode/django-rest-framework/pull/7325

Resolving patch:
diff --git a/rest_framework/urls.py b/rest_framework/urls.py
--- a/rest_framework/urls.py
+++ b/rest_framework/urls.py
@@ -6,7 +6,7 @@
 
     urlpatterns = [
         ...
-        url(r'^auth/', include('rest_framework.urls'))
+        path('auth/', include('rest_framework.urls'))
     ]
 
 You should make sure your authentication settings include `SessionAuthentication`.
diff --git a/rest_framework/versioning.py b/rest_framework/versioning.py
--- a/rest_framework/versioning.py
+++ b/rest_framework/versioning.py
@@ -60,8 +60,8 @@ class URLPathVersioning(BaseVersioning):
     An example URL conf for two views that accept two different versions.
 
     urlpatterns = [
-        url(r'^(?P<version>[v1|v2]+)/users/$', users_list, name='users-list'),
-        url(r'^(?P<version>[v1|v2]+)/users/(?P<pk>[0-9]+)/$', users_detail, name='users-detail')
+        re_path(r'^(?P<version>[v1|v2]+)/users/$', users_list, name='users-list'),
+        re_path(r'^(?P<version>[v1|v2]+)/users/(?P<pk>[0-9]+)/$', users_detail, name='users-detail')
     ]
 
     GET /1.0/something/ HTTP/1.1
@@ -99,14 +99,14 @@ class NamespaceVersioning(BaseVersioning):
 
     # users/urls.py
     urlpatterns = [
-        url(r'^/users/$', users_list, name='users-list'),
-        url(r'^/users/(?P<pk>[0-9]+)/$', users_detail, name='users-detail')
+        path('/users/', users_list, name='users-list'),
+        path('/users/<int:pk>/', users_detail, name='users-detail')
     ]
 
     # urls.py
     urlpatterns = [
-        url(r'^v1/', include('users.urls', namespace='v1')),
-        url(r'^v2/', include('users.urls', namespace='v2'))
+        path('v1/', include('users.urls', namespace='v1')),
+        path('v2/', include('users.urls', namespace='v2'))
     ]
 
     GET /1.0/something/ HTTP/1.1


Test patch:
diff --git a/tests/authentication/test_authentication.py b/tests/authentication/test_authentication.py
--- a/tests/authentication/test_authentication.py
+++ b/tests/authentication/test_authentication.py
@@ -2,10 +2,10 @@
 
 import pytest
 from django.conf import settings
-from django.conf.urls import include, url
 from django.contrib.auth.models import User
 from django.http import HttpResponse
 from django.test import TestCase, override_settings
+from django.urls import include, path
 
 from rest_framework import (
     HTTP_HEADER_ENCODING, exceptions, permissions, renderers, status
@@ -47,34 +47,34 @@ def put(self, request):
 
 
 urlpatterns = [
-    url(
-        r'^session/$',
+    path(
+        'session/',
         MockView.as_view(authentication_classes=[SessionAuthentication])
     ),
-    url(
-        r'^basic/$',
+    path(
+        'basic/',
         MockView.as_view(authentication_classes=[BasicAuthentication])
     ),
-    url(
-        r'^remote-user/$',
+    path(
+        'remote-user/',
         MockView.as_view(authentication_classes=[RemoteUserAuthentication])
     ),
-    url(
-        r'^token/$',
+    path(
+        'token/',
         MockView.as_view(authentication_classes=[TokenAuthentication])
     ),
-    url(
-        r'^customtoken/$',
+    path(
+        'customtoken/',
         MockView.as_view(authentication_classes=[CustomTokenAuthentication])
     ),
-    url(
-        r'^customkeywordtoken/$',
+    path(
+        'customkeywordtoken/',
         MockView.as_view(
             authentication_classes=[CustomKeywordTokenAuthentication]
         )
     ),
-    url(r'^auth-token/$', obtain_auth_token),
-    url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')),
+    path('auth-token/', obtain_auth_token),
+    path('auth/', include('rest_framework.urls', namespace='rest_framework')),
 ]
 
 
diff --git a/tests/browsable_api/auth_urls.py b/tests/browsable_api/auth_urls.py
--- a/tests/browsable_api/auth_urls.py
+++ b/tests/browsable_api/auth_urls.py
@@ -1,8 +1,8 @@
-from django.conf.urls import include, url
+from django.urls import include, path
 
 from .views import MockView
 
 urlpatterns = [
-    url(r'^$', MockView.as_view()),
-    url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')),
+    path('', MockView.as_view()),
+    path('auth/', include('rest_framework.urls', namespace='rest_framework')),
 ]
diff --git a/tests/browsable_api/no_auth_urls.py b/tests/browsable_api/no_auth_urls.py
--- a/tests/browsable_api/no_auth_urls.py
+++ b/tests/browsable_api/no_auth_urls.py
@@ -1,7 +1,7 @@
-from django.conf.urls import url
+from django.urls import path
 
 from .views import MockView
 
 urlpatterns = [
-    url(r'^$', MockView.as_view()),
+    path('', MockView.as_view()),
 ]
diff --git a/tests/browsable_api/test_browsable_nested_api.py b/tests/browsable_api/test_browsable_nested_api.py
--- a/tests/browsable_api/test_browsable_nested_api.py
+++ b/tests/browsable_api/test_browsable_nested_api.py
@@ -1,6 +1,6 @@
-from django.conf.urls import url
 from django.test import TestCase
 from django.test.utils import override_settings
+from django.urls import path
 
 from rest_framework import serializers
 from rest_framework.generics import ListCreateAPIView
@@ -23,7 +23,7 @@ class NestedSerializersView(ListCreateAPIView):
 
 
 urlpatterns = [
-    url(r'^api/$', NestedSerializersView.as_view(), name='api'),
+    path('api/', NestedSerializersView.as_view(), name='api'),
 ]
 
 
diff --git a/tests/schemas/test_coreapi.py b/tests/schemas/test_coreapi.py
--- a/tests/schemas/test_coreapi.py
+++ b/tests/schemas/test_coreapi.py
@@ -1,11 +1,10 @@
 import unittest
 
 import pytest
-from django.conf.urls import include, url
 from django.core.exceptions import PermissionDenied
 from django.http import Http404
 from django.test import TestCase, override_settings
-from django.urls import path
+from django.urls import include, path
 
 from rest_framework import (
     filters, generics, pagination, permissions, serializers
@@ -145,8 +144,8 @@ def schema_view(request):
 router = DefaultRouter()
 router.register('example', ExampleViewSet, basename='example')
 urlpatterns = [
-    url(r'^$', schema_view),
-    url(r'^', include(router.urls))
+    path('', schema_view),
+    path('', include(router.urls))
 ]
 
 
@@ -407,9 +406,9 @@ def get(self, *args, **kwargs):
 class TestSchemaGenerator(TestCase):
     def setUp(self):
         self.patterns = [
-            url(r'^example/?$', views.ExampleListView.as_view()),
-            url(r'^example/(?P<pk>\d+)/?$', views.ExampleDetailView.as_view()),
-            url(r'^example/(?P<pk>\d+)/sub/?$', views.ExampleDetailView.as_view()),
+            path('example/', views.ExampleListView.as_view()),
+            path('example/<int:pk>/', views.ExampleDetailView.as_view()),
+            path('example/<int:pk>/sub/', views.ExampleDetailView.as_view()),
         ]
 
     def test_schema_for_regular_views(self):
@@ -513,9 +512,9 @@ def test_schema_for_regular_views(self):
 class TestSchemaGeneratorNotAtRoot(TestCase):
     def setUp(self):
         self.patterns = [
-            url(r'^api/v1/example/?$', views.ExampleListView.as_view()),
-            url(r'^api/v1/example/(?P<pk>\d+)/?$', views.ExampleDetailView.as_view()),
-            url(r'^api/v1/example/(?P<pk>\d+)/sub/?$', views.ExampleDetailView.as_view()),
+            path('api/v1/example/', views.ExampleListView.as_view()),
+            path('api/v1/example/<int:pk>/', views.ExampleDetailView.as_view()),
+            path('api/v1/example/<int:pk>/sub/', views.ExampleDetailView.as_view()),
         ]
 
     def test_schema_for_regular_views(self):
@@ -569,7 +568,7 @@ def setUp(self):
         router = DefaultRouter()
         router.register('example1', MethodLimitedViewSet, basename='example1')
         self.patterns = [
-            url(r'^', include(router.urls))
+            path('', include(router.urls))
         ]
 
     def test_schema_for_regular_views(self):
@@ -635,8 +634,8 @@ def setUp(self):
         router.register('example1', Http404ExampleViewSet, basename='example1')
         router.register('example2', PermissionDeniedExampleViewSet, basename='example2')
         self.patterns = [
-            url('^example/?$', views.ExampleListView.as_view()),
-            url(r'^', include(router.urls))
+            path('example/', views.ExampleListView.as_view()),
+            path('', include(router.urls))
         ]
 
     def test_schema_for_regular_views(self):
@@ -679,7 +678,7 @@ class ForeignKeySourceView(generics.CreateAPIView):
 class TestSchemaGeneratorWithForeignKey(TestCase):
     def setUp(self):
         self.patterns = [
-            url(r'^example/?$', ForeignKeySourceView.as_view()),
+            path('example/', ForeignKeySourceView.as_view()),
         ]
 
     def test_schema_for_regular_views(self):
@@ -725,7 +724,7 @@ class ManyToManySourceView(generics.CreateAPIView):
 class TestSchemaGeneratorWithManyToMany(TestCase):
     def setUp(self):
         self.patterns = [
-            url(r'^example/?$', ManyToManySourceView.as_view()),
+            path('example/', ManyToManySourceView.as_view()),
         ]
 
     def test_schema_for_regular_views(self):
@@ -1041,9 +1040,9 @@ def included_fbv(request):
 class SchemaGenerationExclusionTests(TestCase):
     def setUp(self):
         self.patterns = [
-            url('^excluded-cbv/$', ExcludedAPIView.as_view()),
-            url('^excluded-fbv/$', excluded_fbv),
-            url('^included-fbv/$', included_fbv),
+            path('excluded-cbv/', ExcludedAPIView.as_view()),
+            path('excluded-fbv/', excluded_fbv),
+            path('included-fbv/', included_fbv),
         ]
 
     def test_schema_generator_excludes_correctly(self):
@@ -1136,8 +1135,8 @@ def simple_fbv(request):
             pass
 
         patterns = [
-            url(r'^test', simple_fbv),
-            url(r'^test/list/', simple_fbv),
+            path('test', simple_fbv),
+            path('test/list/', simple_fbv),
         ]
 
         generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
@@ -1173,14 +1172,14 @@ def _verify_cbv_links(self, loc, url, methods=None, suffixes=None):
 
     def test_manually_routing_generic_view(self):
         patterns = [
-            url(r'^test', NamingCollisionView.as_view()),
-            url(r'^test/retrieve/', NamingCollisionView.as_view()),
-            url(r'^test/update/', NamingCollisionView.as_view()),
+            path('test', NamingCollisionView.as_view()),
+            path('test/retrieve/', NamingCollisionView.as_view()),
+            path('test/update/', NamingCollisionView.as_view()),
 
             # Fails with method names:
-            url(r'^test/get/', NamingCollisionView.as_view()),
-            url(r'^test/put/', NamingCollisionView.as_view()),
-            url(r'^test/delete/', NamingCollisionView.as_view()),
+            path('test/get/', NamingCollisionView.as_view()),
+            path('test/put/', NamingCollisionView.as_view()),
+            path('test/delete/', NamingCollisionView.as_view()),
         ]
 
         generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
@@ -1196,7 +1195,7 @@ def test_manually_routing_generic_view(self):
 
     def test_from_router(self):
         patterns = [
-            url(r'from-router', include(naming_collisions_router.urls)),
+            path('from-router', include(naming_collisions_router.urls)),
         ]
 
         generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
@@ -1228,8 +1227,8 @@ def test_from_router(self):
 
     def test_url_under_same_key_not_replaced(self):
         patterns = [
-            url(r'example/(?P<pk>\d+)/$', BasicNamingCollisionView.as_view()),
-            url(r'example/(?P<slug>\w+)/$', BasicNamingCollisionView.as_view()),
+            path('example/<int:pk>/', BasicNamingCollisionView.as_view()),
+            path('example/<str:slug>/', BasicNamingCollisionView.as_view()),
         ]
 
         generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
@@ -1245,8 +1244,8 @@ def simple_fbv(request):
             pass
 
         patterns = [
-            url(r'^test/list/', simple_fbv),
-            url(r'^test/(?P<pk>\d+)/list/', simple_fbv),
+            path('test/list/', simple_fbv),
+            path('test/<int:pk>/list/', simple_fbv),
         ]
 
         generator = SchemaGenerator(title='Naming Colisions', patterns=patterns)
diff --git a/tests/schemas/test_managementcommand.py b/tests/schemas/test_managementcommand.py
--- a/tests/schemas/test_managementcommand.py
+++ b/tests/schemas/test_managementcommand.py
@@ -3,10 +3,10 @@
 import tempfile
 
 import pytest
-from django.conf.urls import url
 from django.core.management import call_command
 from django.test import TestCase
 from django.test.utils import override_settings
+from django.urls import path
 
 from rest_framework.compat import uritemplate, yaml
 from rest_framework.management.commands import generateschema
@@ -20,7 +20,7 @@ def get(self, request):
 
 
 urlpatterns = [
-    url(r'^$', FooView.as_view())
+    path('', FooView.as_view())
 ]
 
 
diff --git a/tests/schemas/test_openapi.py b/tests/schemas/test_openapi.py
--- a/tests/schemas/test_openapi.py
+++ b/tests/schemas/test_openapi.py
@@ -2,8 +2,8 @@
 import warnings
 
 import pytest
-from django.conf.urls import url
 from django.test import RequestFactory, TestCase, override_settings
+from django.urls import path
 from django.utils.translation import gettext_lazy as _
 
 from rest_framework import filters, generics, pagination, routers, serializers
@@ -719,8 +719,8 @@ def test_repeat_operation_ids(self):
 
     def test_duplicate_operation_id(self):
         patterns = [
-            url(r'^duplicate1/?$', views.ExampleOperationIdDuplicate1.as_view()),
-            url(r'^duplicate2/?$', views.ExampleOperationIdDuplicate2.as_view()),
+            path('duplicate1/', views.ExampleOperationIdDuplicate1.as_view()),
+            path('duplicate2/', views.ExampleOperationIdDuplicate2.as_view()),
         ]
 
         generator = SchemaGenerator(patterns=patterns)
@@ -874,7 +874,7 @@ class ExampleStringTagsViewSet(views.ExampleGenericAPIView):
             schema = AutoSchema(tags=['example1', 'example2'])
 
         url_patterns = [
-            url(r'^test/?$', ExampleStringTagsViewSet.as_view()),
+            path('test/', ExampleStringTagsViewSet.as_view()),
         ]
         generator = SchemaGenerator(patterns=url_patterns)
         schema = generator.get_schema(request=create_request('/'))
@@ -911,8 +911,8 @@ class BranchAPIView(views.ExampleGenericAPIView):
             pass
 
         url_patterns = [
-            url(r'^any-dash_underscore/?$', RestaurantAPIView.as_view()),
-            url(r'^restaurants/branches/?$', BranchAPIView.as_view())
+            path('any-dash_underscore/', RestaurantAPIView.as_view()),
+            path('restaurants/branches/', BranchAPIView.as_view())
         ]
         generator = SchemaGenerator(patterns=url_patterns)
         schema = generator.get_schema(request=create_request('/'))
@@ -930,7 +930,7 @@ def test_override_settings(self):
     def test_paths_construction(self):
         """Construction of the `paths` key."""
         patterns = [
-            url(r'^example/?$', views.ExampleListView.as_view()),
+            path('example/', views.ExampleListView.as_view()),
         ]
         generator = SchemaGenerator(patterns=patterns)
         generator._initialise_endpoints()
@@ -946,8 +946,8 @@ def test_paths_construction(self):
     def test_prefixed_paths_construction(self):
         """Construction of the `paths` key maintains a common prefix."""
         patterns = [
-            url(r'^v1/example/?$', views.ExampleListView.as_view()),
-            url(r'^v1/example/{pk}/?$', views.ExampleDetailView.as_view()),
+            path('v1/example/', views.ExampleListView.as_view()),
+            path('v1/example/{pk}/', views.ExampleDetailView.as_view()),
         ]
         generator = SchemaGenerator(patterns=patterns)
         generator._initialise_endpoints()
@@ -959,8 +959,8 @@ def test_prefixed_paths_construction(self):
 
     def test_mount_url_prefixed_to_paths(self):
         patterns = [
-            url(r'^example/?$', views.ExampleListView.as_view()),
-            url(r'^example/{pk}/?$', views.ExampleDetailView.as_view()),
+            path('example/', views.ExampleListView.as_view()),
+            path('example/{pk}/', views.ExampleDetailView.as_view()),
         ]
         generator = SchemaGenerator(patterns=patterns, url='/api')
         generator._initialise_endpoints()
@@ -973,7 +973,7 @@ def test_mount_url_prefixed_to_paths(self):
     def test_schema_construction(self):
         """Construction of the top level dictionary."""
         patterns = [
-            url(r'^example/?$', views.ExampleListView.as_view()),
+            path('example/', views.ExampleListView.as_view()),
         ]
         generator = SchemaGenerator(patterns=patterns)
 
@@ -995,7 +995,7 @@ def test_schema_with_no_paths(self):
     def test_schema_information(self):
         """Construction of the top level dictionary."""
         patterns = [
-            url(r'^example/?$', views.ExampleListView.as_view()),
+            path('example/', views.ExampleListView.as_view()),
         ]
         generator = SchemaGenerator(patterns=patterns, title='My title', version='1.2.3', description='My description')
 
@@ -1009,7 +1009,7 @@ def test_schema_information(self):
     def test_schema_information_empty(self):
         """Construction of the top level dictionary."""
         patterns = [
-            url(r'^example/?$', views.ExampleListView.as_view()),
+            path('example/', views.ExampleListView.as_view()),
         ]
         generator = SchemaGenerator(patterns=patterns)
 
@@ -1022,7 +1022,7 @@ def test_schema_information_empty(self):
     def test_serializer_model(self):
         """Construction of the top level dictionary."""
         patterns = [
-            url(r'^example/?$', views.ExampleGenericAPIViewModel.as_view()),
+            path('example/', views.ExampleGenericAPIViewModel.as_view()),
         ]
 
         generator = SchemaGenerator(patterns=patterns)
@@ -1038,7 +1038,7 @@ def test_serializer_model(self):
 
     def test_authtoken_serializer(self):
         patterns = [
-            url(r'^api-token-auth/', obtain_auth_token)
+            path('api-token-auth/', obtain_auth_token)
         ]
         generator = SchemaGenerator(patterns=patterns)
 
@@ -1065,7 +1065,7 @@ def test_authtoken_serializer(self):
 
     def test_component_name(self):
         patterns = [
-            url(r'^example/?$', views.ExampleAutoSchemaComponentName.as_view()),
+            path('example/', views.ExampleAutoSchemaComponentName.as_view()),
         ]
 
         generator = SchemaGenerator(patterns=patterns)
@@ -1080,8 +1080,8 @@ def test_component_name(self):
 
     def test_duplicate_component_name(self):
         patterns = [
-            url(r'^duplicate1/?$', views.ExampleAutoSchemaDuplicate1.as_view()),
-            url(r'^duplicate2/?$', views.ExampleAutoSchemaDuplicate2.as_view()),
+            path('duplicate1/', views.ExampleAutoSchemaDuplicate1.as_view()),
+            path('duplicate2/', views.ExampleAutoSchemaDuplicate2.as_view()),
         ]
 
         generator = SchemaGenerator(patterns=patterns)
@@ -1104,7 +1104,7 @@ class ExampleView(generics.DestroyAPIView):
             schema = AutoSchema(operation_id_base='example')
 
         url_patterns = [
-            url(r'^example/?$', ExampleView.as_view()),
+            path('example/', ExampleView.as_view()),
         ]
         generator = SchemaGenerator(patterns=url_patterns)
         schema = generator.get_schema(request=create_request('/'))
diff --git a/tests/test_api_client.py b/tests/test_api_client.py
--- a/tests/test_api_client.py
+++ b/tests/test_api_client.py
@@ -2,9 +2,9 @@
 import tempfile
 import unittest
 
-from django.conf.urls import url
 from django.http import HttpResponse
 from django.test import override_settings
+from django.urls import path, re_path
 
 from rest_framework.compat import coreapi, coreschema
 from rest_framework.parsers import FileUploadParser
@@ -178,13 +178,13 @@ def get(self, request):
 
 
 urlpatterns = [
-    url(r'^$', SchemaView.as_view()),
-    url(r'^example/$', ListView.as_view()),
-    url(r'^example/(?P<id>[0-9]+)/$', DetailView.as_view()),
-    url(r'^upload/$', UploadView.as_view()),
-    url(r'^download/$', DownloadView.as_view()),
-    url(r'^text/$', TextView.as_view()),
-    url(r'^headers/$', HeadersView.as_view()),
+    path('', SchemaView.as_view()),
+    path('example/', ListView.as_view()),
+    re_path(r'^example/(?P<id>[0-9]+)/$', DetailView.as_view()),
+    path('upload/', UploadView.as_view()),
+    path('download/', DownloadView.as_view()),
+    path('text/', TextView.as_view()),
+    path('headers/', HeadersView.as_view()),
 ]
 
 
diff --git a/tests/test_atomic_requests.py b/tests/test_atomic_requests.py
--- a/tests/test_atomic_requests.py
+++ b/tests/test_atomic_requests.py
@@ -1,9 +1,9 @@
 import unittest
 
-from django.conf.urls import url
 from django.db import connection, connections, transaction
 from django.http import Http404
 from django.test import TestCase, TransactionTestCase, override_settings
+from django.urls import path
 
 from rest_framework import status
 from rest_framework.exceptions import APIException
@@ -44,7 +44,7 @@ def get(self, request, *args, **kwargs):
 
 
 urlpatterns = (
-    url(r'^$', NonAtomicAPIExceptionView.as_view()),
+    path('', NonAtomicAPIExceptionView.as_view()),
 )
 
 
diff --git a/tests/test_fields.py b/tests/test_fields.py
--- a/tests/test_fields.py
+++ b/tests/test_fields.py
@@ -697,7 +697,7 @@ class TestNullBooleanField(TestBooleanField):
         None: None,
         'other': True
     }
-    field = serializers.NullBooleanField()
+    field = serializers.BooleanField(allow_null=True)
 
 
 class TestNullableBooleanField(TestNullBooleanField):
diff --git a/tests/test_htmlrenderer.py b/tests/test_htmlrenderer.py
--- a/tests/test_htmlrenderer.py
+++ b/tests/test_htmlrenderer.py
@@ -1,10 +1,10 @@
 import django.template.loader
 import pytest
-from django.conf.urls import url
 from django.core.exceptions import ImproperlyConfigured, PermissionDenied
 from django.http import Http404
 from django.template import TemplateDoesNotExist, engines
 from django.test import TestCase, override_settings
+from django.urls import path
 
 from rest_framework import status
 from rest_framework.decorators import api_view, renderer_classes
@@ -35,9 +35,9 @@ def not_found(request):
 
 
 urlpatterns = [
-    url(r'^$', example),
-    url(r'^permission_denied$', permission_denied),
-    url(r'^not_found$', not_found),
+    path('', example),
+    path('permission_denied', permission_denied),
+    path('not_found', not_found),
 ]
 
 
diff --git a/tests/test_lazy_hyperlinks.py b/tests/test_lazy_hyperlinks.py
--- a/tests/test_lazy_hyperlinks.py
+++ b/tests/test_lazy_hyperlinks.py
@@ -1,6 +1,6 @@
-from django.conf.urls import url
 from django.db import models
 from django.test import TestCase, override_settings
+from django.urls import path
 
 from rest_framework import serializers
 from rest_framework.renderers import JSONRenderer
@@ -29,7 +29,7 @@ def dummy_view(request):
 
 
 urlpatterns = [
-    url(r'^example/(?P<pk>[0-9]+)/$', dummy_view, name='example-detail'),
+    path('example/<int:pk>/', dummy_view, name='example-detail'),
 ]
 
 
diff --git a/tests/test_metadata.py b/tests/test_metadata.py
--- a/tests/test_metadata.py
+++ b/tests/test_metadata.py
@@ -311,7 +311,8 @@ class ExampleListSerializer(serializers.ListSerializer):
 class TestSimpleMetadataFieldInfo(TestCase):
     def test_null_boolean_field_info_type(self):
         options = metadata.SimpleMetadata()
-        field_info = options.get_field_info(serializers.NullBooleanField())
+        field_info = options.get_field_info(serializers.BooleanField(
+            allow_null=True))
         assert field_info['type'] == 'boolean'
 
     def test_related_field_choices(self):
diff --git a/tests/test_middleware.py b/tests/test_middleware.py
--- a/tests/test_middleware.py
+++ b/tests/test_middleware.py
@@ -1,7 +1,7 @@
-from django.conf.urls import url
 from django.contrib.auth.models import User
 from django.http import HttpRequest
 from django.test import override_settings
+from django.urls import path
 
 from rest_framework.authentication import TokenAuthentication
 from rest_framework.authtoken.models import Token
@@ -17,8 +17,8 @@ def post(self, request):
 
 
 urlpatterns = [
-    url(r'^auth$', APIView.as_view(authentication_classes=(TokenAuthentication,))),
-    url(r'^post$', PostView.as_view()),
+    path('auth', APIView.as_view(authentication_classes=(TokenAuthentication,))),
+    path('post', PostView.as_view()),
 ]
 
 
diff --git a/tests/test_relations.py b/tests/test_relations.py
--- a/tests/test_relations.py
+++ b/tests/test_relations.py
@@ -2,9 +2,9 @@
 
 import pytest
 from _pytest.monkeypatch import MonkeyPatch
-from django.conf.urls import url
 from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
 from django.test import override_settings
+from django.urls import re_path
 from django.utils.datastructures import MultiValueDict
 
 from rest_framework import relations, serializers
@@ -146,7 +146,7 @@ def test_pk_representation(self):
 
 
 urlpatterns = [
-    url(r'^example/(?P<name>.+)/$', lambda: None, name='example'),
+    re_path(r'^example/(?P<name>.+)/$', lambda: None, name='example'),
 ]
 
 
diff --git a/tests/test_relations_hyperlink.py b/tests/test_relations_hyperlink.py
--- a/tests/test_relations_hyperlink.py
+++ b/tests/test_relations_hyperlink.py
@@ -1,5 +1,5 @@
-from django.conf.urls import url
 from django.test import TestCase, override_settings
+from django.urls import path
 
 from rest_framework import serializers
 from rest_framework.test import APIRequestFactory
@@ -17,14 +17,14 @@ def dummy_view(request, pk):
 
 
 urlpatterns = [
-    url(r'^dummyurl/(?P<pk>[0-9]+)/$', dummy_view, name='dummy-url'),
-    url(r'^manytomanysource/(?P<pk>[0-9]+)/$', dummy_view, name='manytomanysource-detail'),
-    url(r'^manytomanytarget/(?P<pk>[0-9]+)/$', dummy_view, name='manytomanytarget-detail'),
-    url(r'^foreignkeysource/(?P<pk>[0-9]+)/$', dummy_view, name='foreignkeysource-detail'),
-    url(r'^foreignkeytarget/(?P<pk>[0-9]+)/$', dummy_view, name='foreignkeytarget-detail'),
-    url(r'^nullableforeignkeysource/(?P<pk>[0-9]+)/$', dummy_view, name='nullableforeignkeysource-detail'),
-    url(r'^onetoonetarget/(?P<pk>[0-9]+)/$', dummy_view, name='onetoonetarget-detail'),
-    url(r'^nullableonetoonesource/(?P<pk>[0-9]+)/$', dummy_view, name='nullableonetoonesource-detail'),
+    path('dummyurl/<int:pk>/', dummy_view, name='dummy-url'),
+    path('manytomanysource/<int:pk>/', dummy_view, name='manytomanysource-detail'),
+    path('manytomanytarget/<int:pk>/', dummy_view, name='manytomanytarget-detail'),
+    path('foreignkeysource/<int:pk>/', dummy_view, name='foreignkeysource-detail'),
+    path('foreignkeytarget/<int:pk>/', dummy_view, name='foreignkeytarget-detail'),
+    path('nullableforeignkeysource/<int:pk>/', dummy_view, name='nullableforeignkeysource-detail'),
+    path('onetoonetarget/<int:pk>/', dummy_view, name='onetoonetarget-detail'),
+    path('nullableonetoonesource/<int:pk>/', dummy_view, name='nullableonetoonesource-detail'),
 ]
 
 
diff --git a/tests/test_renderers.py b/tests/test_renderers.py
--- a/tests/test_renderers.py
+++ b/tests/test_renderers.py
@@ -3,12 +3,12 @@
 from collections.abc import MutableMapping
 
 import pytest
-from django.conf.urls import include, url
 from django.core.cache import cache
 from django.db import models
 from django.http.request import HttpRequest
 from django.template import loader
 from django.test import TestCase, override_settings
+from django.urls import include, path, re_path
 from django.utils.safestring import SafeText
 from django.utils.translation import gettext_lazy as _
 
@@ -111,14 +111,14 @@ def get(self, request, **kwargs):
 
 
 urlpatterns = [
-    url(r'^.*\.(?P<format>.+)$', MockView.as_view(renderer_classes=[RendererA, RendererB])),
-    url(r'^$', MockView.as_view(renderer_classes=[RendererA, RendererB])),
-    url(r'^cache$', MockGETView.as_view()),
-    url(r'^parseerror$', MockPOSTView.as_view(renderer_classes=[JSONRenderer, BrowsableAPIRenderer])),
-    url(r'^html$', HTMLView.as_view()),
-    url(r'^html1$', HTMLView1.as_view()),
-    url(r'^empty$', EmptyGETView.as_view()),
-    url(r'^api', include('rest_framework.urls', namespace='rest_framework'))
+    re_path(r'^.*\.(?P<format>.+)$', MockView.as_view(renderer_classes=[RendererA, RendererB])),
+    path('', MockView.as_view(renderer_classes=[RendererA, RendererB])),
+    path('cache', MockGETView.as_view()),
+    path('parseerror', MockPOSTView.as_view(renderer_classes=[JSONRenderer, BrowsableAPIRenderer])),
+    path('html', HTMLView.as_view()),
+    path('html1', HTMLView1.as_view()),
+    path('empty', EmptyGETView.as_view()),
+    path('api', include('rest_framework.urls', namespace='rest_framework'))
 ]
 
 
@@ -637,7 +637,7 @@ class AuthExampleViewSet(ExampleViewSet):
     router = SimpleRouter()
     router.register('examples', ExampleViewSet, basename='example')
     router.register('auth-examples', AuthExampleViewSet, basename='auth-example')
-    urlpatterns = [url(r'^api/', include(router.urls))]
+    urlpatterns = [path('api/', include(router.urls))]
 
     def setUp(self):
         self.renderer = BrowsableAPIRenderer()
diff --git a/tests/test_request.py b/tests/test_request.py
--- a/tests/test_request.py
+++ b/tests/test_request.py
@@ -5,7 +5,6 @@
 import tempfile
 
 import pytest
-from django.conf.urls import url
 from django.contrib.auth import authenticate, login, logout
 from django.contrib.auth.middleware import AuthenticationMiddleware
 from django.contrib.auth.models import User
@@ -13,6 +12,7 @@
 from django.core.files.uploadedfile import SimpleUploadedFile
 from django.http.request import RawPostDataException
 from django.test import TestCase, override_settings
+from django.urls import path
 
 from rest_framework import status
 from rest_framework.authentication import SessionAuthentication
@@ -153,9 +153,9 @@ def post(self, request):
 
 
 urlpatterns = [
-    url(r'^$', MockView.as_view()),
-    url(r'^echo/$', EchoView.as_view()),
-    url(r'^upload/$', FileUploadView.as_view())
+    path('', MockView.as_view()),
+    path('echo/', EchoView.as_view()),
+    path('upload/', FileUploadView.as_view())
 ]
 
 
diff --git a/tests/test_requests_client.py b/tests/test_requests_client.py
--- a/tests/test_requests_client.py
+++ b/tests/test_requests_client.py
@@ -1,10 +1,10 @@
 import unittest
 
-from django.conf.urls import url
 from django.contrib.auth import authenticate, login
 from django.contrib.auth.models import User
 from django.shortcuts import redirect
 from django.test import override_settings
+from django.urls import path
 from django.utils.decorators import method_decorator
 from django.views.decorators.csrf import csrf_protect, ensure_csrf_cookie
 
@@ -90,10 +90,10 @@ def post(self, request):
 
 
 urlpatterns = [
-    url(r'^$', Root.as_view(), name='root'),
-    url(r'^headers/$', HeadersView.as_view(), name='headers'),
-    url(r'^session/$', SessionView.as_view(), name='session'),
-    url(r'^auth/$', AuthView.as_view(), name='auth'),
+    path('', Root.as_view(), name='root'),
+    path('headers/', HeadersView.as_view(), name='headers'),
+    path('session/', SessionView.as_view(), name='session'),
+    path('auth/', AuthView.as_view(), name='auth'),
 ]
 
 
diff --git a/tests/test_response.py b/tests/test_response.py
--- a/tests/test_response.py
+++ b/tests/test_response.py
@@ -1,5 +1,5 @@
-from django.conf.urls import include, url
 from django.test import TestCase, override_settings
+from django.urls import include, path, re_path
 
 from rest_framework import generics, routers, serializers, status, viewsets
 from rest_framework.parsers import JSONParser
@@ -117,15 +117,15 @@ class HTMLNewModelView(generics.ListCreateAPIView):
 
 
 urlpatterns = [
-    url(r'^setbyview$', MockViewSettingContentType.as_view(renderer_classes=[RendererA, RendererB, RendererC])),
-    url(r'^.*\.(?P<format>.+)$', MockView.as_view(renderer_classes=[RendererA, RendererB, RendererC])),
-    url(r'^$', MockView.as_view(renderer_classes=[RendererA, RendererB, RendererC])),
-    url(r'^html$', HTMLView.as_view()),
-    url(r'^json$', JSONView.as_view()),
-    url(r'^html1$', HTMLView1.as_view()),
-    url(r'^html_new_model$', HTMLNewModelView.as_view()),
-    url(r'^html_new_model_viewset', include(new_model_viewset_router.urls)),
-    url(r'^restframework', include('rest_framework.urls', namespace='rest_framework'))
+    path('setbyview', MockViewSettingContentType.as_view(renderer_classes=[RendererA, RendererB, RendererC])),
+    re_path(r'^.*\.(?P<format>.+)$', MockView.as_view(renderer_classes=[RendererA, RendererB, RendererC])),
+    path('', MockView.as_view(renderer_classes=[RendererA, RendererB, RendererC])),
+    path('html', HTMLView.as_view()),
+    path('json', JSONView.as_view()),
+    path('html1', HTMLView1.as_view()),
+    path('html_new_model', HTMLNewModelView.as_view()),
+    path('html_new_model_viewset', include(new_model_viewset_router.urls)),
+    path('restframework', include('rest_framework.urls', namespace='rest_framework'))
 ]
 
 
diff --git a/tests/test_reverse.py b/tests/test_reverse.py
--- a/tests/test_reverse.py
+++ b/tests/test_reverse.py
@@ -1,6 +1,5 @@
-from django.conf.urls import url
 from django.test import TestCase, override_settings
-from django.urls import NoReverseMatch
+from django.urls import NoReverseMatch, path
 
 from rest_framework.reverse import reverse
 from rest_framework.test import APIRequestFactory
@@ -13,7 +12,7 @@ def null_view(request):
 
 
 urlpatterns = [
-    url(r'^view$', null_view, name='view'),
+    path('view', null_view, name='view'),
 ]
 
 
diff --git a/tests/test_routers.py b/tests/test_routers.py
--- a/tests/test_routers.py
+++ b/tests/test_routers.py
@@ -1,11 +1,10 @@
 from collections import namedtuple
 
 import pytest
-from django.conf.urls import include, url
 from django.core.exceptions import ImproperlyConfigured
 from django.db import models
 from django.test import TestCase, override_settings
-from django.urls import resolve, reverse
+from django.urls import include, path, resolve, reverse
 
 from rest_framework import permissions, serializers, viewsets
 from rest_framework.decorators import action
@@ -118,7 +117,7 @@ class TestSimpleRouter(URLPatternsTestCase, TestCase):
     router.register('basics', BasicViewSet, basename='basic')
 
     urlpatterns = [
-        url(r'^api/', include(router.urls)),
+        path('api/', include(router.urls)),
     ]
 
     def setUp(self):
@@ -163,8 +162,8 @@ def test_register_after_accessing_urls(self):
 
 class TestRootView(URLPatternsTestCase, TestCase):
     urlpatterns = [
-        url(r'^non-namespaced/', include(namespaced_router.urls)),
-        url(r'^namespaced/', include((namespaced_router.urls, 'namespaced'), namespace='namespaced')),
+        path('non-namespaced/', include(namespaced_router.urls)),
+        path('namespaced/', include((namespaced_router.urls, 'namespaced'), namespace='namespaced')),
     ]
 
     def test_retrieve_namespaced_root(self):
@@ -181,8 +180,8 @@ class TestCustomLookupFields(URLPatternsTestCase, TestCase):
     Ensure that custom lookup fields are correctly routed.
     """
     urlpatterns = [
-        url(r'^example/', include(notes_router.urls)),
-        url(r'^example2/', include(kwarged_notes_router.urls)),
+        path('example/', include(notes_router.urls)),
+        path('example2/', include(kwarged_notes_router.urls)),
     ]
 
     def setUp(self):
@@ -238,8 +237,8 @@ class TestLookupUrlKwargs(URLPatternsTestCase, TestCase):
     Setup a deep lookup_field, but map it to a simple URL kwarg.
     """
     urlpatterns = [
-        url(r'^example/', include(notes_router.urls)),
-        url(r'^example2/', include(kwarged_notes_router.urls)),
+        path('example/', include(notes_router.urls)),
+        path('example2/', include(kwarged_notes_router.urls)),
     ]
 
     def setUp(self):
@@ -426,7 +425,7 @@ def test_inherited_list_and_detail_route_decorators(self):
 
 class TestEmptyPrefix(URLPatternsTestCase, TestCase):
     urlpatterns = [
-        url(r'^empty-prefix/', include(empty_prefix_router.urls)),
+        path('empty-prefix/', include(empty_prefix_router.urls)),
     ]
 
     def test_empty_prefix_list(self):
@@ -443,7 +442,7 @@ def test_empty_prefix_detail(self):
 
 class TestRegexUrlPath(URLPatternsTestCase, TestCase):
     urlpatterns = [
-        url(r'^regex/', include(regex_url_path_router.urls)),
+        path('regex/', include(regex_url_path_router.urls)),
     ]
 
     def test_regex_url_path_list(self):
@@ -462,7 +461,7 @@ def test_regex_url_path_detail(self):
 
 class TestViewInitkwargs(URLPatternsTestCase, TestCase):
     urlpatterns = [
-        url(r'^example/', include(notes_router.urls)),
+        path('example/', include(notes_router.urls)),
     ]
 
     def test_suffix(self):
diff --git a/tests/test_testing.py b/tests/test_testing.py
--- a/tests/test_testing.py
+++ b/tests/test_testing.py
@@ -1,9 +1,9 @@
 from io import BytesIO
 
-from django.conf.urls import url
 from django.contrib.auth.models import User
 from django.shortcuts import redirect
 from django.test import TestCase, override_settings
+from django.urls import path
 
 from rest_framework import fields, serializers
 from rest_framework.decorators import api_view
@@ -47,10 +47,10 @@ def post_view(request):
 
 
 urlpatterns = [
-    url(r'^view/$', view),
-    url(r'^session-view/$', session_view),
-    url(r'^redirect-view/$', redirect_view),
-    url(r'^post-view/$', post_view)
+    path('view/', view),
+    path('session-view/', session_view),
+    path('redirect-view/', redirect_view),
+    path('post-view/', post_view)
 ]
 
 
@@ -284,7 +284,7 @@ def test_empty_request_content_type(self):
 
 class TestUrlPatternTestCase(URLPatternsTestCase):
     urlpatterns = [
-        url(r'^$', view),
+        path('', view),
     ]
 
     @classmethod
diff --git a/tests/test_urlpatterns.py b/tests/test_urlpatterns.py
--- a/tests/test_urlpatterns.py
+++ b/tests/test_urlpatterns.py
@@ -1,8 +1,7 @@
 from collections import namedtuple
 
-from django.conf.urls import include, url
 from django.test import TestCase
-from django.urls import Resolver404, URLResolver, path, re_path
+from django.urls import Resolver404, URLResolver, include, path, re_path
 from django.urls.resolvers import RegexPattern
 
 from rest_framework.test import APIRequestFactory
@@ -61,7 +60,7 @@ def _test_trailing_slash(self, urlpatterns):
 
     def test_trailing_slash(self):
         urlpatterns = [
-            url(r'^test/$', dummy_view),
+            path('test/', dummy_view),
         ]
         self._test_trailing_slash(urlpatterns)
 
@@ -81,7 +80,7 @@ def _test_format_suffix(self, urlpatterns):
 
     def test_format_suffix(self):
         urlpatterns = [
-            url(r'^test$', dummy_view),
+            path('test', dummy_view),
         ]
         self._test_format_suffix(urlpatterns)
 
@@ -116,7 +115,7 @@ def _test_default_args(self, urlpatterns):
 
     def test_default_args(self):
         urlpatterns = [
-            url(r'^test$', dummy_view, {'foo': 'bar'}),
+            path('test', dummy_view, {'foo': 'bar'}),
         ]
         self._test_default_args(urlpatterns)
 
@@ -135,15 +134,6 @@ def _test_included_urls(self, urlpatterns):
         self._resolve_urlpatterns(urlpatterns, test_paths)
 
     def test_included_urls(self):
-        nested_patterns = [
-            url(r'^path$', dummy_view)
-        ]
-        urlpatterns = [
-            url(r'^test/', include(nested_patterns), {'foo': 'bar'}),
-        ]
-        self._test_included_urls(urlpatterns)
-
-    def test_included_urls_django2(self):
         nested_patterns = [
             path('path', dummy_view)
         ]
@@ -152,44 +142,35 @@ def test_included_urls_django2(self):
         ]
         self._test_included_urls(urlpatterns)
 
-    def test_included_urls_django2_mixed(self):
-        nested_patterns = [
-            path('path', dummy_view)
-        ]
-        urlpatterns = [
-            url('^test/', include(nested_patterns), {'foo': 'bar'}),
-        ]
-        self._test_included_urls(urlpatterns)
-
-    def test_included_urls_django2_mixed_args(self):
+    def test_included_urls_mixed(self):
         nested_patterns = [
             path('path/<int:child>', dummy_view),
-            url('^url/(?P<child>[0-9]+)$', dummy_view)
+            re_path(r'^re_path/(?P<child>[0-9]+)$', dummy_view)
         ]
         urlpatterns = [
-            url('^purl/(?P<parent>[0-9]+)/', include(nested_patterns), {'foo': 'bar'}),
+            re_path(r'^pre_path/(?P<parent>[0-9]+)/', include(nested_patterns), {'foo': 'bar'}),
             path('ppath/<int:parent>/', include(nested_patterns), {'foo': 'bar'}),
         ]
         test_paths = [
-            # parent url() nesting child path()
-            URLTestPath('/purl/87/path/42', (), {'parent': '87', 'child': 42, 'foo': 'bar', }),
-            URLTestPath('/purl/87/path/42.api', (), {'parent': '87', 'child': 42, 'foo': 'bar', 'format': 'api'}),
-            URLTestPath('/purl/87/path/42.asdf', (), {'parent': '87', 'child': 42, 'foo': 'bar', 'format': 'asdf'}),
+            # parent re_path() nesting child path()
+            URLTestPath('/pre_path/87/path/42', (), {'parent': '87', 'child': 42, 'foo': 'bar', }),
+            URLTestPath('/pre_path/87/path/42.api', (), {'parent': '87', 'child': 42, 'foo': 'bar', 'format': 'api'}),
+            URLTestPath('/pre_path/87/path/42.asdf', (), {'parent': '87', 'child': 42, 'foo': 'bar', 'format': 'asdf'}),
 
-            # parent path() nesting child url()
-            URLTestPath('/ppath/87/url/42', (), {'parent': 87, 'child': '42', 'foo': 'bar', }),
-            URLTestPath('/ppath/87/url/42.api', (), {'parent': 87, 'child': '42', 'foo': 'bar', 'format': 'api'}),
-            URLTestPath('/ppath/87/url/42.asdf', (), {'parent': 87, 'child': '42', 'foo': 'bar', 'format': 'asdf'}),
+            # parent path() nesting child re_path()
+            URLTestPath('/ppath/87/re_path/42', (), {'parent': 87, 'child': '42', 'foo': 'bar', }),
+            URLTestPath('/ppath/87/re_path/42.api', (), {'parent': 87, 'child': '42', 'foo': 'bar', 'format': 'api'}),
+            URLTestPath('/ppath/87/re_path/42.asdf', (), {'parent': 87, 'child': '42', 'foo': 'bar', 'format': 'asdf'}),
 
             # parent path() nesting child path()
             URLTestPath('/ppath/87/path/42', (), {'parent': 87, 'child': 42, 'foo': 'bar', }),
             URLTestPath('/ppath/87/path/42.api', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'api'}),
             URLTestPath('/ppath/87/path/42.asdf', (), {'parent': 87, 'child': 42, 'foo': 'bar', 'format': 'asdf'}),
 
-            # parent url() nesting child url()
-            URLTestPath('/purl/87/url/42', (), {'parent': '87', 'child': '42', 'foo': 'bar', }),
-            URLTestPath('/purl/87/url/42.api', (), {'parent': '87', 'child': '42', 'foo': 'bar', 'format': 'api'}),
-            URLTestPath('/purl/87/url/42.asdf', (), {'parent': '87', 'child': '42', 'foo': 'bar', 'format': 'asdf'}),
+            # parent re_path() nesting child re_path()
+            URLTestPath('/pre_path/87/re_path/42', (), {'parent': '87', 'child': '42', 'foo': 'bar', }),
+            URLTestPath('/pre_path/87/re_path/42.api', (), {'parent': '87', 'child': '42', 'foo': 'bar', 'format': 'api'}),
+            URLTestPath('/pre_path/87/re_path/42.asdf', (), {'parent': '87', 'child': '42', 'foo': 'bar', 'format': 'asdf'}),
         ]
         self._resolve_urlpatterns(urlpatterns, test_paths)
 
@@ -202,13 +183,13 @@ def _test_allowed_formats(self, urlpatterns):
         ]
         self._resolve_urlpatterns(urlpatterns, test_paths, allowed=allowed_formats)
 
-    def test_allowed_formats(self):
+    def test_allowed_formats_re_path(self):
         urlpatterns = [
-            url('^test$', dummy_view),
+            re_path(r'^test$', dummy_view),
         ]
         self._test_allowed_formats(urlpatterns)
 
-    def test_allowed_formats_django2(self):
+    def test_allowed_formats_path(self):
         urlpatterns = [
             path('test', dummy_view),
         ]
diff --git a/tests/test_utils.py b/tests/test_utils.py
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -1,7 +1,7 @@
 from unittest import mock
 
-from django.conf.urls import url
 from django.test import TestCase, override_settings
+from django.urls import path
 
 from rest_framework.decorators import action
 from rest_framework.routers import SimpleRouter
@@ -64,12 +64,12 @@ def suffixed_action(self, request, *args, **kwargs):
 router = SimpleRouter()
 router.register(r'resources', ResourceViewSet)
 urlpatterns = [
-    url(r'^$', Root.as_view()),
-    url(r'^resource/$', ResourceRoot.as_view()),
-    url(r'^resource/customname$', CustomNameResourceInstance.as_view()),
-    url(r'^resource/(?P<key>[0-9]+)$', ResourceInstance.as_view()),
-    url(r'^resource/(?P<key>[0-9]+)/$', NestedResourceRoot.as_view()),
-    url(r'^resource/(?P<key>[0-9]+)/(?P<other>[A-Za-z]+)$', NestedResourceInstance.as_view()),
+    path('', Root.as_view()),
+    path('resource/', ResourceRoot.as_view()),
+    path('resource/customname', CustomNameResourceInstance.as_view()),
+    path('resource/<int:key>', ResourceInstance.as_view()),
+    path('resource/<int:key>/', NestedResourceRoot.as_view()),
+    path('resource/<int:key>/<str:other>', NestedResourceInstance.as_view()),
 ]
 urlpatterns += router.urls
 
diff --git a/tests/test_versioning.py b/tests/test_versioning.py
--- a/tests/test_versioning.py
+++ b/tests/test_versioning.py
@@ -1,6 +1,6 @@
 import pytest
-from django.conf.urls import include, url
 from django.test import override_settings
+from django.urls import include, path, re_path
 
 from rest_framework import serializers, status, versioning
 from rest_framework.decorators import APIView
@@ -144,14 +144,14 @@ class FakeResolverMatch:
 
 class TestURLReversing(URLPatternsTestCase, APITestCase):
     included = [
-        url(r'^namespaced/$', dummy_view, name='another'),
-        url(r'^example/(?P<pk>\d+)/$', dummy_pk_view, name='example-detail')
+        path('namespaced/', dummy_view, name='another'),
+        path('example/<int:pk>/', dummy_pk_view, name='example-detail')
     ]
 
     urlpatterns = [
-        url(r'^v1/', include((included, 'v1'), namespace='v1')),
-        url(r'^another/$', dummy_view, name='another'),
-        url(r'^(?P<version>[v1|v2]+)/another/$', dummy_view, name='another'),
+        path('v1/', include((included, 'v1'), namespace='v1')),
+        path('another/', dummy_view, name='another'),
+        re_path(r'^(?P<version>[v1|v2]+)/another/$', dummy_view, name='another'),
     ]
 
     def test_reverse_unversioned(self):
@@ -310,12 +310,12 @@ def test_missing_with_default_and_none_allowed(self):
 
 class TestHyperlinkedRelatedField(URLPatternsTestCase, APITestCase):
     included = [
-        url(r'^namespaced/(?P<pk>\d+)/$', dummy_pk_view, name='namespaced'),
+        path('namespaced/<int:pk>/', dummy_pk_view, name='namespaced'),
     ]
 
     urlpatterns = [
-        url(r'^v1/', include((included, 'v1'), namespace='v1')),
-        url(r'^v2/', include((included, 'v2'), namespace='v2'))
+        path('v1/', include((included, 'v1'), namespace='v1')),
+        path('v2/', include((included, 'v2'), namespace='v2'))
     ]
 
     def setUp(self):
@@ -342,17 +342,17 @@ def test_bug_2489(self):
 
 class TestNamespaceVersioningHyperlinkedRelatedFieldScheme(URLPatternsTestCase, APITestCase):
     nested = [
-        url(r'^namespaced/(?P<pk>\d+)/$', dummy_pk_view, name='nested'),
+        path('namespaced/<int:pk>/', dummy_pk_view, name='nested'),
     ]
     included = [
-        url(r'^namespaced/(?P<pk>\d+)/$', dummy_pk_view, name='namespaced'),
-        url(r'^nested/', include((nested, 'nested-namespace'), namespace='nested-namespace'))
+        path('namespaced/<int:pk>/', dummy_pk_view, name='namespaced'),
+        path('nested/', include((nested, 'nested-namespace'), namespace='nested-namespace'))
     ]
 
     urlpatterns = [
-        url(r'^v1/', include((included, 'restframeworkv1'), namespace='v1')),
-        url(r'^v2/', include((included, 'restframeworkv2'), namespace='v2')),
-        url(r'^non-api/(?P<pk>\d+)/$', dummy_pk_view, name='non-api-view')
+        path('v1/', include((included, 'restframeworkv1'), namespace='v1')),
+        path('v2/', include((included, 'restframeworkv2'), namespace='v2')),
+        path('non-api/<int:pk>/', dummy_pk_view, name='non-api-view')
     ]
 
     def _create_field(self, view_name, version):
diff --git a/tests/test_viewsets.py b/tests/test_viewsets.py
--- a/tests/test_viewsets.py
+++ b/tests/test_viewsets.py
@@ -2,9 +2,9 @@
 from functools import wraps
 
 import pytest
-from django.conf.urls import include, url
 from django.db import models
 from django.test import TestCase, override_settings
+from django.urls import include, path
 
 from rest_framework import status
 from rest_framework.decorators import action
@@ -124,7 +124,7 @@ class ActionViewSetWithMapping(ActionViewSet):
 
 
 urlpatterns = [
-    url(r'^api/', include(router.urls)),
+    path('api/', include(router.urls)),
 ]
 
 
diff --git a/tests/urls.py b/tests/urls.py
--- a/tests/urls.py
+++ b/tests/urls.py
@@ -3,14 +3,14 @@
 
 We need only the docs urls for DocumentationRenderer tests.
 """
-from django.conf.urls import url
+from django.urls import path
 
 from rest_framework.compat import coreapi
 from rest_framework.documentation import include_docs_urls
 
 if coreapi:
     urlpatterns = [
-        url(r'^docs/', include_docs_urls(title='Test Suite API')),
+        path('docs/', include_docs_urls(title='Test Suite API')),
     ]
 else:
     urlpatterns = []