diff --git a/django/test/__init__.py b/django/test/__init__.py index 63baf87534..e3561f5ae7 100644 --- a/django/test/__init__.py +++ b/django/test/__init__.py @@ -18,12 +18,3 @@ __all__ = [ 'skipUnlessAnyDBFeature', 'skipUnlessDBFeature', 'ignore_warnings', 'modify_settings', 'override_settings', 'override_system_checks', 'tag', ] - -# To simplify Django's test suite; not meant as a public API -try: - from unittest import mock # NOQA -except ImportError: - try: - import mock # NOQA - except ImportError: - pass diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index bccefc2d19..8494d76f4c 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -13,6 +13,7 @@ import sys import tempfile import unittest from io import StringIO +from unittest import mock import django from django import conf, get_version @@ -24,7 +25,7 @@ from django.db import ConnectionHandler from django.db.migrations.exceptions import MigrationSchemaMissing from django.db.migrations.recorder import MigrationRecorder from django.test import ( - LiveServerTestCase, SimpleTestCase, TestCase, mock, override_settings, + LiveServerTestCase, SimpleTestCase, TestCase, override_settings, ) from django.utils.encoding import force_text diff --git a/tests/admin_views/test_multidb.py b/tests/admin_views/test_multidb.py index 0273b7aaef..3687bec16f 100644 --- a/tests/admin_views/test_multidb.py +++ b/tests/admin_views/test_multidb.py @@ -1,8 +1,10 @@ +from unittest import mock + from django.conf.urls import url from django.contrib import admin from django.contrib.auth.models import User from django.db import connections -from django.test import TestCase, mock, override_settings +from django.test import TestCase, override_settings from django.urls import reverse from .models import Book diff --git a/tests/auth_tests/test_admin_multidb.py b/tests/auth_tests/test_admin_multidb.py index 122cb78876..6b36b50a16 100644 --- a/tests/auth_tests/test_admin_multidb.py +++ b/tests/auth_tests/test_admin_multidb.py @@ -1,9 +1,11 @@ +from unittest import mock + from django.conf.urls import url from django.contrib import admin from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User from django.db import connections -from django.test import TestCase, mock, override_settings +from django.test import TestCase, override_settings from django.urls import reverse diff --git a/tests/auth_tests/test_auth_backends.py b/tests/auth_tests/test_auth_backends.py index 033df9c682..3d929698c9 100644 --- a/tests/auth_tests/test_auth_backends.py +++ b/tests/auth_tests/test_auth_backends.py @@ -1,4 +1,5 @@ from datetime import date +from unittest import mock from django.contrib.auth import ( BACKEND_SESSION_KEY, SESSION_KEY, authenticate, get_user, signals, @@ -10,7 +11,7 @@ from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ImproperlyConfigured, PermissionDenied from django.http import HttpRequest from django.test import ( - SimpleTestCase, TestCase, mock, modify_settings, override_settings, + SimpleTestCase, TestCase, modify_settings, override_settings, ) from .models import ( diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py index ae6fa313de..bbcd75124a 100644 --- a/tests/auth_tests/test_forms.py +++ b/tests/auth_tests/test_forms.py @@ -1,5 +1,6 @@ import datetime import re +from unittest import mock from django import forms from django.contrib.auth.forms import ( @@ -13,7 +14,7 @@ from django.contrib.sites.models import Site from django.core import mail from django.core.mail import EmailMultiAlternatives from django.forms.fields import CharField, Field, IntegerField -from django.test import SimpleTestCase, TestCase, mock, override_settings +from django.test import SimpleTestCase, TestCase, override_settings from django.utils import translation from django.utils.encoding import force_text from django.utils.text import capfirst diff --git a/tests/auth_tests/test_hashers.py b/tests/auth_tests/test_hashers.py index 57982017eb..4e7bae280d 100644 --- a/tests/auth_tests/test_hashers.py +++ b/tests/auth_tests/test_hashers.py @@ -1,4 +1,4 @@ -from unittest import skipUnless +from unittest import mock, skipUnless from django.conf.global_settings import PASSWORD_HASHERS from django.contrib.auth.hashers import ( @@ -7,7 +7,7 @@ from django.contrib.auth.hashers import ( check_password, get_hasher, identify_hasher, is_password_usable, make_password, ) -from django.test import SimpleTestCase, mock +from django.test import SimpleTestCase from django.test.utils import override_settings from django.utils.encoding import force_bytes diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py index 15ff551211..b1b629021f 100644 --- a/tests/auth_tests/test_management.py +++ b/tests/auth_tests/test_management.py @@ -2,6 +2,7 @@ import builtins import sys from datetime import date from io import StringIO +from unittest import mock from django.apps import apps from django.contrib.auth import management @@ -14,7 +15,7 @@ from django.contrib.contenttypes.models import ContentType from django.core.management import call_command from django.core.management.base import CommandError from django.db import migrations -from django.test import TestCase, mock, override_settings +from django.test import TestCase, override_settings from django.utils.translation import ugettext_lazy as _ from .models import ( diff --git a/tests/auth_tests/test_mixins.py b/tests/auth_tests/test_mixins.py index 4f74890304..0a0c5ccdf4 100644 --- a/tests/auth_tests/test_mixins.py +++ b/tests/auth_tests/test_mixins.py @@ -1,3 +1,5 @@ +from unittest import mock + from django.contrib.auth import models from django.contrib.auth.mixins import ( LoginRequiredMixin, PermissionRequiredMixin, UserPassesTestMixin, @@ -5,7 +7,7 @@ from django.contrib.auth.mixins import ( from django.contrib.auth.models import AnonymousUser from django.core.exceptions import PermissionDenied from django.http import HttpResponse -from django.test import RequestFactory, TestCase, mock +from django.test import RequestFactory, TestCase from django.views.generic import View diff --git a/tests/auth_tests/test_models.py b/tests/auth_tests/test_models.py index ebe3dc0837..f688c5ae74 100644 --- a/tests/auth_tests/test_models.py +++ b/tests/auth_tests/test_models.py @@ -1,3 +1,5 @@ +from unittest import mock + from django.conf.global_settings import PASSWORD_HASHERS from django.contrib.auth import get_user_model from django.contrib.auth.base_user import AbstractBaseUser @@ -8,7 +10,7 @@ from django.contrib.auth.models import ( from django.contrib.contenttypes.models import ContentType from django.core import mail from django.db.models.signals import post_save -from django.test import TestCase, mock, override_settings +from django.test import TestCase, override_settings from .models.with_custom_email_field import CustomEmailField diff --git a/tests/backends/test_features.py b/tests/backends/test_features.py index e7cb3dbfe8..7bd57f0423 100644 --- a/tests/backends/test_features.py +++ b/tests/backends/test_features.py @@ -1,7 +1,7 @@ -from unittest import skipUnless +from unittest import mock, skipUnless from django.db import connection -from django.test import TestCase, mock +from django.test import TestCase class TestDatabaseFeatures(TestCase): diff --git a/tests/backends/tests.py b/tests/backends/tests.py index 662cdc4140..214852ea77 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -5,6 +5,7 @@ import threading import unittest import warnings from decimal import Decimal, Rounded +from unittest import mock from django.core.exceptions import ImproperlyConfigured from django.core.management.color import no_style @@ -20,7 +21,7 @@ from django.db.models import Avg, StdDev, Sum, Variance from django.db.models.sql.constants import CURSOR from django.db.utils import ConnectionHandler from django.test import ( - SimpleTestCase, TestCase, TransactionTestCase, mock, override_settings, + SimpleTestCase, TestCase, TransactionTestCase, override_settings, skipIfDBFeature, skipUnlessDBFeature, ) diff --git a/tests/cache/tests.py b/tests/cache/tests.py index bfceff9b02..5c3ec0fe04 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -11,6 +11,7 @@ import threading import time import unittest import warnings +from unittest import mock from django.conf import settings from django.core import management, signals @@ -31,7 +32,7 @@ from django.template.context_processors import csrf from django.template.response import TemplateResponse from django.test import ( RequestFactory, SimpleTestCase, TestCase, TransactionTestCase, - ignore_warnings, mock, override_settings, + ignore_warnings, override_settings, ) from django.test.signals import setting_changed from django.utils import timezone, translation diff --git a/tests/check_framework/test_database.py b/tests/check_framework/test_database.py index 594f4ccee6..80824ab8e0 100644 --- a/tests/check_framework/test_database.py +++ b/tests/check_framework/test_database.py @@ -1,9 +1,10 @@ import unittest +from unittest import mock from django.core.checks import Tags, run_checks from django.core.checks.registry import CheckRegistry from django.db import connection -from django.test import TestCase, mock +from django.test import TestCase class DatabaseCheckTests(TestCase): diff --git a/tests/check_framework/test_multi_db.py b/tests/check_framework/test_multi_db.py index 700553f47b..3080b52fda 100644 --- a/tests/check_framework/test_multi_db.py +++ b/tests/check_framework/test_multi_db.py @@ -1,5 +1,7 @@ +from unittest import mock + from django.db import connections, models -from django.test import TestCase, mock +from django.test import TestCase from django.test.utils import isolate_apps, override_settings diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py index 7fedcb7abd..eecdaa91da 100644 --- a/tests/contenttypes_tests/tests.py +++ b/tests/contenttypes_tests/tests.py @@ -1,4 +1,5 @@ import datetime +from unittest import mock from django.apps.registry import Apps, apps from django.conf import settings @@ -12,7 +13,7 @@ from django.core import checks, management from django.core.management import call_command from django.db import connections, migrations, models from django.test import ( - SimpleTestCase, TestCase, TransactionTestCase, mock, override_settings, + SimpleTestCase, TestCase, TransactionTestCase, override_settings, ) from django.test.utils import captured_stdout, isolate_apps from django.utils.encoding import force_text diff --git a/tests/dbshell/test_postgresql_psycopg2.py b/tests/dbshell/test_postgresql_psycopg2.py index f0848ac7b8..26090fb7f1 100644 --- a/tests/dbshell/test_postgresql_psycopg2.py +++ b/tests/dbshell/test_postgresql_psycopg2.py @@ -1,7 +1,8 @@ import os +from unittest import mock from django.db.backends.postgresql.client import DatabaseClient -from django.test import SimpleTestCase, mock +from django.test import SimpleTestCase class PostgreSqlDbshellCommandTestCase(SimpleTestCase): diff --git a/tests/files/tests.py b/tests/files/tests.py index 7323b6987e..f7d05574d2 100644 --- a/tests/files/tests.py +++ b/tests/files/tests.py @@ -4,13 +4,13 @@ import struct import tempfile import unittest from io import BytesIO, StringIO, TextIOWrapper +from unittest import mock from django.core.files import File from django.core.files.base import ContentFile from django.core.files.move import file_move_safe from django.core.files.temp import NamedTemporaryFile from django.core.files.uploadedfile import SimpleUploadedFile, UploadedFile -from django.test import mock try: from PIL import Image diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index ca60dd70e8..89edea424e 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -4,6 +4,7 @@ import tempfile import unittest import warnings from io import StringIO +from unittest import mock from django.apps import apps from django.contrib.sites.models import Site @@ -13,9 +14,7 @@ from django.core.management import CommandError from django.core.management.commands.dumpdata import ProxyModelWarning from django.core.serializers.base import ProgressBar from django.db import IntegrityError, connection -from django.test import ( - TestCase, TransactionTestCase, mock, skipUnlessDBFeature, -) +from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature from django.utils.encoding import force_text from .models import ( diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py index 125ed273e9..ed8331ad72 100644 --- a/tests/forms_tests/tests/test_formsets.py +++ b/tests/forms_tests/tests/test_formsets.py @@ -1,5 +1,6 @@ import datetime from collections import Counter +from unittest import mock from django.forms import ( BaseForm, CharField, DateField, FileField, Form, IntegerField, @@ -7,7 +8,7 @@ from django.forms import ( ) from django.forms.formsets import BaseFormSet, formset_factory from django.forms.utils import ErrorList -from django.test import SimpleTestCase, mock +from django.test import SimpleTestCase from django.utils.encoding import force_text diff --git a/tests/gis_tests/gdal_tests/test_driver.py b/tests/gis_tests/gdal_tests/test_driver.py index 74d6019db6..6e7e149ed7 100644 --- a/tests/gis_tests/gdal_tests/test_driver.py +++ b/tests/gis_tests/gdal_tests/test_driver.py @@ -1,7 +1,7 @@ import unittest +from unittest import mock from django.contrib.gis.gdal import HAS_GDAL -from django.test import mock if HAS_GDAL: from django.contrib.gis.gdal import Driver, GDALException diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py index 8626c4f200..b74d3ab708 100644 --- a/tests/gis_tests/geos_tests/test_geos.py +++ b/tests/gis_tests/geos_tests/test_geos.py @@ -4,7 +4,7 @@ import pickle import random from binascii import a2b_hex, b2a_hex from io import BytesIO -from unittest import skipUnless +from unittest import mock, skipUnless from django.contrib.gis import gdal from django.contrib.gis.gdal import HAS_GDAL @@ -17,7 +17,7 @@ from django.contrib.gis.geos.libgeos import geos_version_info from django.contrib.gis.shortcuts import numpy from django.template import Context from django.template.engine import Engine -from django.test import SimpleTestCase, mock +from django.test import SimpleTestCase from django.utils.encoding import force_bytes from ..test_data import TestDataMixin diff --git a/tests/gis_tests/test_geoip2.py b/tests/gis_tests/test_geoip2.py index d35dcc336e..a362aed953 100644 --- a/tests/gis_tests/test_geoip2.py +++ b/tests/gis_tests/test_geoip2.py @@ -1,11 +1,10 @@ import os import unittest -from unittest import skipUnless +from unittest import mock, skipUnless from django.conf import settings from django.contrib.gis.geoip2 import HAS_GEOIP2 from django.contrib.gis.geos import HAS_GEOS, GEOSGeometry -from django.test import mock if HAS_GEOIP2: from django.contrib.gis.geoip2 import GeoIP2, GeoIP2Exception diff --git a/tests/gis_tests/test_ptr.py b/tests/gis_tests/test_ptr.py index 1b8beaf4e7..ca318a28eb 100644 --- a/tests/gis_tests/test_ptr.py +++ b/tests/gis_tests/test_ptr.py @@ -1,7 +1,8 @@ import ctypes +from unittest import mock from django.contrib.gis.ptr import CPointerBase -from django.test import SimpleTestCase, mock +from django.test import SimpleTestCase class CPointerBaseTests(SimpleTestCase): diff --git a/tests/i18n/test_compilation.py b/tests/i18n/test_compilation.py index 5244832e2d..ca7dfd4309 100644 --- a/tests/i18n/test_compilation.py +++ b/tests/i18n/test_compilation.py @@ -4,6 +4,7 @@ import stat import unittest from io import StringIO from subprocess import Popen +from unittest import mock from django.core.management import ( CommandError, call_command, execute_from_command_line, @@ -11,7 +12,7 @@ from django.core.management import ( from django.core.management.commands.makemessages import \ Command as MakeMessagesCommand from django.core.management.utils import find_command -from django.test import SimpleTestCase, mock, override_settings +from django.test import SimpleTestCase, override_settings from django.test.utils import captured_stderr, captured_stdout from django.utils import translation from django.utils.encoding import force_text diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py index 4189a9e168..0adf3d0f1c 100644 --- a/tests/i18n/test_extraction.py +++ b/tests/i18n/test_extraction.py @@ -4,7 +4,7 @@ import shutil import time import warnings from io import StringIO -from unittest import skipUnless +from unittest import mock, skipUnless from admin_scripts.tests import AdminScriptTestCase @@ -14,7 +14,7 @@ from django.core.management.base import CommandError from django.core.management.commands.makemessages import \ Command as MakeMessagesCommand from django.core.management.utils import find_command -from django.test import SimpleTestCase, mock, override_settings +from django.test import SimpleTestCase, override_settings from django.test.utils import captured_stderr, captured_stdout from django.utils.encoding import force_text from django.utils.translation import TranslatorCommentWarning diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index 726a65cd8f..49b1819c26 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -1,10 +1,10 @@ import re from io import StringIO -from unittest import skipUnless +from unittest import mock, skipUnless from django.core.management import call_command from django.db import connection -from django.test import TestCase, mock, skipUnlessDBFeature +from django.test import TestCase, skipUnlessDBFeature from django.utils.encoding import force_text from .models import ColumnTypes diff --git a/tests/introspection/tests.py b/tests/introspection/tests.py index a85748d958..2993592e4f 100644 --- a/tests/introspection/tests.py +++ b/tests/introspection/tests.py @@ -1,8 +1,8 @@ -from unittest import skipUnless +from unittest import mock, skipUnless from django.db import connection from django.db.utils import DatabaseError -from django.test import TransactionTestCase, mock, skipUnlessDBFeature +from django.test import TransactionTestCase, skipUnlessDBFeature from django.test.utils import ignore_warnings from django.utils.deprecation import RemovedInDjango21Warning diff --git a/tests/invalid_models_tests/test_backend_specific.py b/tests/invalid_models_tests/test_backend_specific.py index 6321b6d7be..0bdd8995b0 100644 --- a/tests/invalid_models_tests/test_backend_specific.py +++ b/tests/invalid_models_tests/test_backend_specific.py @@ -1,6 +1,8 @@ +from unittest import mock + from django.core.checks import Error from django.db import connections, models -from django.test import SimpleTestCase, mock +from django.test import SimpleTestCase from django.test.utils import isolate_apps diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index df35181d92..997c81f29e 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -1,5 +1,6 @@ import functools import re +from unittest import mock from django.apps import apps from django.conf import settings @@ -11,7 +12,7 @@ from django.db.migrations.graph import MigrationGraph from django.db.migrations.loader import MigrationLoader from django.db.migrations.questioner import MigrationQuestioner from django.db.migrations.state import ModelState, ProjectState -from django.test import TestCase, mock, override_settings +from django.test import TestCase, override_settings from django.test.utils import isolate_lru_cache from .models import FoodManager, FoodQuerySet diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py index 421b4890a4..f5d7887c35 100644 --- a/tests/migrations/test_commands.py +++ b/tests/migrations/test_commands.py @@ -3,6 +3,7 @@ import importlib import io import os import sys +from unittest import mock from django.apps import apps from django.core.management import CommandError, call_command @@ -14,7 +15,7 @@ from django.db.migrations.exceptions import ( InconsistentMigrationHistory, MigrationSchemaMissing, ) from django.db.migrations.recorder import MigrationRecorder -from django.test import mock, override_settings +from django.test import override_settings from django.utils.encoding import force_text from .models import UnicodeModel, UnserializableModel diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index ec48e2ee8e..c1384f6933 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -7,6 +7,7 @@ import os import re import sys import uuid +from unittest import mock import custom_migration_operations.more_operations import custom_migration_operations.operations @@ -18,7 +19,7 @@ from django.db import migrations, models from django.db.migrations.writer import ( MigrationWriter, OperationWriter, SettingsReference, ) -from django.test import SimpleTestCase, mock +from django.test import SimpleTestCase from django.utils import datetime_safe from django.utils.deconstruct import deconstructible from django.utils.functional import SimpleLazyObject diff --git a/tests/postgres_tests/migrations/0001_setup_extensions.py b/tests/postgres_tests/migrations/0001_setup_extensions.py index 7add08c499..6342ba7732 100644 --- a/tests/postgres_tests/migrations/0001_setup_extensions.py +++ b/tests/postgres_tests/migrations/0001_setup_extensions.py @@ -1,3 +1,5 @@ +from unittest import mock + from django.db import migrations try: @@ -6,7 +8,6 @@ try: TrigramExtension, UnaccentExtension, ) except ImportError: - from django.test import mock BtreeGinExtension = mock.Mock() CreateExtension = mock.Mock() HStoreExtension = mock.Mock() diff --git a/tests/requirements/py2.txt b/tests/requirements/py2.txt deleted file mode 100644 index 0ed845bb7e..0000000000 --- a/tests/requirements/py2.txt +++ /dev/null @@ -1,5 +0,0 @@ --r base.txt -enum34 -# Due to https://github.com/linsomniac/python-memcached/issues/79 in newer versions. -python-memcached <= 1.53 -mock diff --git a/tests/runtests.py b/tests/runtests.py index 57ba84d3db..4cb36049fd 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -437,16 +437,6 @@ if __name__ == "__main__": options = parser.parse_args() - # mock is a required dependency - try: - from django.test import mock # NOQA - except ImportError: - print( - "Please install test dependencies first: \n" - "$ pip install -r requirements/py%s.txt" % sys.version_info.major - ) - sys.exit(1) - # Allow including a trailing slash on app_labels for tab completion convenience options.modules = [os.path.normpath(labels) for labels in options.modules] diff --git a/tests/schema/tests.py b/tests/schema/tests.py index 73c1371cfe..4f62333dba 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -2,6 +2,7 @@ import datetime import itertools import unittest from copy import copy +from unittest import mock from django.db import ( DatabaseError, IntegrityError, OperationalError, connection, @@ -19,7 +20,7 @@ from django.db.models.fields.related import ( from django.db.models.indexes import Index from django.db.transaction import TransactionManagementError, atomic from django.test import ( - TransactionTestCase, mock, skipIfDBFeature, skipUnlessDBFeature, + TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature, ) from django.test.utils import CaptureQueriesContext from django.utils import timezone diff --git a/tests/select_for_update/tests.py b/tests/select_for_update/tests.py index 7224124546..ac1d5b037e 100644 --- a/tests/select_for_update/tests.py +++ b/tests/select_for_update/tests.py @@ -1,5 +1,6 @@ import threading import time +from unittest import mock from multiple_database.routers import TestRouter @@ -7,7 +8,7 @@ from django.db import ( DatabaseError, connection, connections, router, transaction, ) from django.test import ( - TransactionTestCase, mock, override_settings, skipIfDBFeature, + TransactionTestCase, override_settings, skipIfDBFeature, skipUnlessDBFeature, ) from django.test.utils import CaptureQueriesContext diff --git a/tests/serializers/tests.py b/tests/serializers/tests.py index 5750c146a2..da453831e0 100644 --- a/tests/serializers/tests.py +++ b/tests/serializers/tests.py @@ -1,14 +1,13 @@ from datetime import datetime from io import StringIO +from unittest import mock from django.core import serializers from django.core.serializers import SerializerDoesNotExist from django.core.serializers.base import ProgressBar from django.db import connection, transaction from django.http import HttpResponse -from django.test import ( - SimpleTestCase, mock, override_settings, skipUnlessDBFeature, -) +from django.test import SimpleTestCase, override_settings, skipUnlessDBFeature from django.test.utils import Approximate from django.utils.functional import curry diff --git a/tests/shell/tests.py b/tests/shell/tests.py index f2d1d0e392..6d39af3a71 100644 --- a/tests/shell/tests.py +++ b/tests/shell/tests.py @@ -1,9 +1,10 @@ import sys import unittest +from unittest import mock from django import __version__ from django.core.management import CommandError, call_command -from django.test import SimpleTestCase, mock +from django.test import SimpleTestCase from django.test.utils import captured_stdin, captured_stdout, patch_logger diff --git a/tests/signals/tests.py b/tests/signals/tests.py index 0c1c885dc4..c6453b83d0 100644 --- a/tests/signals/tests.py +++ b/tests/signals/tests.py @@ -1,8 +1,10 @@ +from unittest import mock + from django.apps.registry import Apps from django.db import models from django.db.models import signals from django.dispatch import receiver -from django.test import TestCase, mock +from django.test import TestCase from django.test.utils import isolate_apps from .models import Author, Book, Car, Person diff --git a/tests/sitemaps_tests/test_management.py b/tests/sitemaps_tests/test_management.py index 459a1d1b3c..f0be10224b 100644 --- a/tests/sitemaps_tests/test_management.py +++ b/tests/sitemaps_tests/test_management.py @@ -1,5 +1,6 @@ +from unittest import mock + from django.core.management import call_command -from django.test import mock from .base import SitemapTestsBase diff --git a/tests/sitemaps_tests/test_utils.py b/tests/sitemaps_tests/test_utils.py index dc4d6511f3..158f1625ce 100644 --- a/tests/sitemaps_tests/test_utils.py +++ b/tests/sitemaps_tests/test_utils.py @@ -1,10 +1,11 @@ +from unittest import mock from urllib.parse import urlencode from django.contrib.sitemaps import ( SitemapNotFound, _get_sitemap_full_url, ping_google, ) from django.core.exceptions import ImproperlyConfigured -from django.test import mock, modify_settings, override_settings +from django.test import modify_settings, override_settings from .base import SitemapTestsBase diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py index f0160c60d8..a9aeb68c3a 100644 --- a/tests/staticfiles_tests/test_management.py +++ b/tests/staticfiles_tests/test_management.py @@ -5,6 +5,7 @@ import shutil import tempfile import unittest from io import StringIO +from unittest import mock from admin_scripts.tests import AdminScriptTestCase @@ -13,7 +14,7 @@ from django.contrib.staticfiles import storage from django.contrib.staticfiles.management.commands import collectstatic from django.core.exceptions import ImproperlyConfigured from django.core.management import call_command -from django.test import mock, override_settings +from django.test import override_settings from django.test.utils import extend_sys_path from django.utils import timezone from django.utils._os import symlinks_supported diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py index 51810fe7bc..2de8122135 100644 --- a/tests/test_runner/tests.py +++ b/tests/test_runner/tests.py @@ -2,6 +2,7 @@ Tests for django test runner """ import unittest +from unittest import mock from admin_scripts.tests import AdminScriptTestCase @@ -10,7 +11,7 @@ from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.core.management import call_command from django.test import ( - TestCase, TransactionTestCase, mock, skipUnlessDBFeature, testcases, + TestCase, TransactionTestCase, skipUnlessDBFeature, testcases, ) from django.test.runner import DiscoverRunner from django.test.testcases import connections_support_transactions diff --git a/tests/test_utils/test_transactiontestcase.py b/tests/test_utils/test_transactiontestcase.py index 34588ddefd..593c06f7e3 100644 --- a/tests/test_utils/test_transactiontestcase.py +++ b/tests/test_utils/test_transactiontestcase.py @@ -1,4 +1,6 @@ -from django.test import TransactionTestCase, mock +from unittest import mock + +from django.test import TransactionTestCase class TestSerializedRollbackInhibitsPostMigrate(TransactionTestCase): diff --git a/tests/urlpatterns_reverse/test_localeregexprovider.py b/tests/urlpatterns_reverse/test_localeregexprovider.py index f05c446eb9..1fbba849c6 100644 --- a/tests/urlpatterns_reverse/test_localeregexprovider.py +++ b/tests/urlpatterns_reverse/test_localeregexprovider.py @@ -1,7 +1,8 @@ import os +from unittest import mock from django.core.exceptions import ImproperlyConfigured -from django.test import SimpleTestCase, mock, override_settings +from django.test import SimpleTestCase, override_settings from django.urls import LocaleRegexProvider from django.urls.resolvers import LocaleRegexDescriptor from django.utils import translation diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py index a18d49868b..6d11068f5b 100644 --- a/tests/user_commands/tests.py +++ b/tests/user_commands/tests.py @@ -1,5 +1,6 @@ import os from io import StringIO +from unittest import mock from admin_scripts.tests import AdminScriptTestCase @@ -8,7 +9,7 @@ from django.core import management from django.core.management import BaseCommand, CommandError, find_commands from django.core.management.utils import find_command, popen_wrapper from django.db import connection -from django.test import SimpleTestCase, mock, override_settings +from django.test import SimpleTestCase, override_settings from django.test.utils import captured_stderr, extend_sys_path from django.utils import translation diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py index 6925da1834..130f5c8c2a 100644 --- a/tests/utils_tests/test_autoreload.py +++ b/tests/utils_tests/test_autoreload.py @@ -3,12 +3,13 @@ import os import shutil import tempfile from importlib import import_module +from unittest import mock import _thread from django import conf from django.contrib import admin -from django.test import SimpleTestCase, mock, override_settings +from django.test import SimpleTestCase, override_settings from django.test.utils import extend_sys_path from django.utils import autoreload from django.utils.translation import trans_real diff --git a/tests/utils_tests/test_timezone.py b/tests/utils_tests/test_timezone.py index 85b396ab12..3c0b092d8a 100644 --- a/tests/utils_tests/test_timezone.py +++ b/tests/utils_tests/test_timezone.py @@ -1,9 +1,10 @@ import datetime import pickle +from unittest import mock import pytz -from django.test import SimpleTestCase, mock, override_settings +from django.test import SimpleTestCase, override_settings from django.utils import timezone CET = pytz.timezone("Europe/Paris")