From 7aba69145dcb436539a7798086748b73a39121e5 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 19 Jan 2017 12:16:04 -0500 Subject: [PATCH] Refs #23919 -- Removed django.test.mock Python 2 compatibility shim. --- django/test/__init__.py | 9 --------- tests/admin_scripts/tests.py | 3 ++- tests/admin_views/test_multidb.py | 4 +++- tests/auth_tests/test_admin_multidb.py | 4 +++- tests/auth_tests/test_auth_backends.py | 3 ++- tests/auth_tests/test_forms.py | 3 ++- tests/auth_tests/test_hashers.py | 4 ++-- tests/auth_tests/test_management.py | 3 ++- tests/auth_tests/test_mixins.py | 4 +++- tests/auth_tests/test_models.py | 4 +++- tests/backends/test_features.py | 4 ++-- tests/backends/tests.py | 3 ++- tests/cache/tests.py | 3 ++- tests/check_framework/test_database.py | 3 ++- tests/check_framework/test_multi_db.py | 4 +++- tests/contenttypes_tests/tests.py | 3 ++- tests/dbshell/test_postgresql_psycopg2.py | 3 ++- tests/files/tests.py | 2 +- tests/fixtures/tests.py | 5 ++--- tests/forms_tests/tests/test_formsets.py | 3 ++- tests/gis_tests/gdal_tests/test_driver.py | 2 +- tests/gis_tests/geos_tests/test_geos.py | 4 ++-- tests/gis_tests/test_geoip2.py | 3 +-- tests/gis_tests/test_ptr.py | 3 ++- tests/i18n/test_compilation.py | 3 ++- tests/i18n/test_extraction.py | 4 ++-- tests/inspectdb/tests.py | 4 ++-- tests/introspection/tests.py | 4 ++-- tests/invalid_models_tests/test_backend_specific.py | 4 +++- tests/migrations/test_autodetector.py | 3 ++- tests/migrations/test_commands.py | 3 ++- tests/migrations/test_writer.py | 3 ++- .../postgres_tests/migrations/0001_setup_extensions.py | 3 ++- tests/requirements/py2.txt | 5 ----- tests/runtests.py | 10 ---------- tests/schema/tests.py | 3 ++- tests/select_for_update/tests.py | 3 ++- tests/serializers/tests.py | 5 ++--- tests/shell/tests.py | 3 ++- tests/signals/tests.py | 4 +++- tests/sitemaps_tests/test_management.py | 3 ++- tests/sitemaps_tests/test_utils.py | 3 ++- tests/staticfiles_tests/test_management.py | 3 ++- tests/test_runner/tests.py | 3 ++- tests/test_utils/test_transactiontestcase.py | 4 +++- tests/urlpatterns_reverse/test_localeregexprovider.py | 3 ++- tests/user_commands/tests.py | 3 ++- tests/utils_tests/test_autoreload.py | 3 ++- tests/utils_tests/test_timezone.py | 3 ++- 49 files changed, 97 insertions(+), 81 deletions(-) delete mode 100644 tests/requirements/py2.txt diff --git a/django/test/__init__.py b/django/test/__init__.py index 63baf875341..e3561f5ae7b 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 bccefc2d19d..8494d76f4cd 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 0273b7aaef2..3687bec16fa 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 122cb788762..6b36b50a162 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 033df9c6820..3d929698c90 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 ae6fa313dea..bbcd75124a1 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 57982017eb3..4e7bae280de 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 15ff551211b..b1b629021fc 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 4f74890304f..0a0c5ccdf4a 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 ebe3dc08379..f688c5ae74a 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 e7cb3dbfe81..7bd57f04233 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 662cdc4140a..214852ea779 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 bfceff9b025..5c3ec0fe04a 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 594f4ccee6a..80824ab8e08 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 700553f47bd..3080b52fdaf 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 7fedcb7abde..eecdaa91daa 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 f0848ac7b89..26090fb7f18 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 7323b6987e0..f7d05574d20 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 ca60dd70e8e..89edea424e9 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 125ed273e96..ed8331ad72d 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 74d6019db64..6e7e149ed71 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 8626c4f2003..b74d3ab7084 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 d35dcc336ec..a362aed9538 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 1b8beaf4e79..ca318a28eb6 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 5244832e2d5..ca7dfd4309d 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 4189a9e168c..0adf3d0f1c1 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 726a65cd8f8..49b1819c265 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 a85748d958c..2993592e4f6 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 6321b6d7be4..0bdd8995b09 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 df35181d926..997c81f29ed 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 421b4890a43..f5d7887c355 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 ec48e2ee8e3..c1384f6933d 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 7add08c4991..6342ba7732d 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 0ed845bb7e1..00000000000 --- 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 57ba84d3db4..4cb36049fda 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 73c1371cfe5..4f62333dbaf 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 72241245467..ac1d5b037e4 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 5750c146a2f..da453831e0a 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 f2d1d0e392c..6d39af3a71b 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 0c1c885dc41..c6453b83d04 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 459a1d1b3c5..f0be10224ba 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 dc4d6511f36..158f1625cef 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 f0160c60d8b..a9aeb68c3a6 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 51810fe7bcd..2de81221356 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 34588ddefd8..593c06f7e3a 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 f05c446eb90..1fbba849c6b 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 a18d49868bd..6d11068f5b0 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 6925da1834a..130f5c8c2a6 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 85b396ab120..3c0b092d8ab 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")