From 890bfa368c33d6ae19fe45cf1eed7e2e8d63160e Mon Sep 17 00:00:00 2001 From: Collin Anderson Date: Wed, 15 Dec 2021 11:09:17 -0500 Subject: [PATCH] Refs #20349 -- Avoided loading testing libraries when not needed. --- django/contrib/messages/apps.py | 2 +- django/contrib/postgres/apps.py | 2 +- django/db/backends/base/creation.py | 3 ++- django/test/testcases.py | 3 ++- django/test/utils.py | 4 ++-- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/django/contrib/messages/apps.py b/django/contrib/messages/apps.py index 064b9a4bde..0b02f7d851 100644 --- a/django/contrib/messages/apps.py +++ b/django/contrib/messages/apps.py @@ -1,7 +1,7 @@ from django.apps import AppConfig from django.contrib.messages.storage import base from django.contrib.messages.utils import get_level_tags -from django.test.signals import setting_changed +from django.core.signals import setting_changed from django.utils.translation import gettext_lazy as _ diff --git a/django/contrib/postgres/apps.py b/django/contrib/postgres/apps.py index 91fc29ac05..b8ec85b7a4 100644 --- a/django/contrib/postgres/apps.py +++ b/django/contrib/postgres/apps.py @@ -3,13 +3,13 @@ from psycopg2.extras import ( ) from django.apps import AppConfig +from django.core.signals import setting_changed from django.db import connections from django.db.backends.signals import connection_created from django.db.migrations.writer import MigrationWriter from django.db.models import CharField, OrderBy, TextField from django.db.models.functions import Collate from django.db.models.indexes import IndexExpression -from django.test.signals import setting_changed from django.utils.translation import gettext_lazy as _ from .indexes import OpClass diff --git a/django/db/backends/base/creation.py b/django/db/backends/base/creation.py index 81cb34bd9f..d1c0e1ac96 100644 --- a/django/db/backends/base/creation.py +++ b/django/db/backends/base/creation.py @@ -1,7 +1,6 @@ import os import sys from io import StringIO -from unittest import expectedFailure, skip from django.apps import apps from django.conf import settings @@ -303,6 +302,8 @@ class BaseDatabaseCreation: Mark tests in Django's test suite which are expected failures on this database and test which should be skipped on this database. """ + # Only load unittest if we're actually testing. + from unittest import expectedFailure, skip for test_name in self.connection.features.django_test_expected_failures: test_case_name, _, test_method_name = test_name.rpartition('.') test_app = test_name.split('.')[0] diff --git a/django/test/testcases.py b/django/test/testcases.py index 1344d550a9..d24a065790 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -31,13 +31,14 @@ from django.core.management import call_command from django.core.management.color import no_style from django.core.management.sql import emit_post_migrate_signal from django.core.servers.basehttp import ThreadedWSGIServer, WSGIRequestHandler +from django.core.signals import setting_changed from django.db import DEFAULT_DB_ALIAS, connection, connections, transaction from django.forms.fields import CharField from django.http import QueryDict from django.http.request import split_domain_port, validate_host from django.test.client import AsyncClient, Client from django.test.html import HTMLParseError, parse_html -from django.test.signals import setting_changed, template_rendered +from django.test.signals import template_rendered from django.test.utils import ( CaptureQueriesContext, ContextList, compare_xml, modify_settings, override_settings, diff --git a/django/test/utils.py b/django/test/utils.py index 81005d4f8f..6c2f566909 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -19,11 +19,11 @@ from django.apps.registry import Apps from django.conf import UserSettingsHolder, settings from django.core import mail from django.core.exceptions import ImproperlyConfigured -from django.core.signals import request_started +from django.core.signals import request_started, setting_changed from django.db import DEFAULT_DB_ALIAS, connections, reset_queries from django.db.models.options import Options from django.template import Template -from django.test.signals import setting_changed, template_rendered +from django.test.signals import template_rendered from django.urls import get_script_prefix, set_script_prefix from django.utils.deprecation import RemovedInDjango50Warning from django.utils.translation import deactivate