Refs #32655 -- Removed extra_tests argument for DiscoverRunner.build_suite()/run_tests().

Per deprecation timeline.
This commit is contained in:
Mariusz Felisiak 2023-01-06 13:12:23 +01:00
parent 4eb97a90f0
commit 43b01300b7
4 changed files with 6 additions and 72 deletions

View File

@ -11,7 +11,6 @@ import random
import sys
import textwrap
import unittest
import warnings
from collections import defaultdict
from contextlib import contextmanager
from importlib import import_module
@ -30,7 +29,6 @@ from django.test.utils import teardown_databases as _teardown_databases
from django.test.utils import teardown_test_environment
from django.utils.crypto import new_hash
from django.utils.datastructures import OrderedSet
from django.utils.deprecation import RemovedInDjango50Warning
try:
import ipdb as pdb
@ -877,15 +875,8 @@ class DiscoverRunner:
self.test_loader._top_level_dir = None
return tests
def build_suite(self, test_labels=None, extra_tests=None, **kwargs):
if extra_tests is not None:
warnings.warn(
"The extra_tests argument is deprecated.",
RemovedInDjango50Warning,
stacklevel=2,
)
def build_suite(self, test_labels=None, **kwargs):
test_labels = test_labels or ["."]
extra_tests = extra_tests or []
discover_kwargs = {}
if self.pattern is not None:
@ -899,8 +890,6 @@ class DiscoverRunner:
tests = self.load_tests_for_label(label, discover_kwargs)
all_tests.extend(iter_test_cases(tests))
all_tests.extend(iter_test_cases(extra_tests))
if self.tags or self.exclude_tags:
if self.tags:
self.log(
@ -1030,7 +1019,7 @@ class DiscoverRunner:
)
return databases
def run_tests(self, test_labels, extra_tests=None, **kwargs):
def run_tests(self, test_labels, **kwargs):
"""
Run the unit tests for all the test labels in the provided list.
@ -1039,14 +1028,8 @@ class DiscoverRunner:
Return the number of tests that failed.
"""
if extra_tests is not None:
warnings.warn(
"The extra_tests argument is deprecated.",
RemovedInDjango50Warning,
stacklevel=2,
)
self.setup_test_environment()
suite = self.build_suite(test_labels, extra_tests)
suite = self.build_suite(test_labels)
databases = self.get_databases(suite)
suite.serialized_aliases = set(
alias for alias, serialize in databases.items() if serialize

View File

@ -267,6 +267,9 @@ to remove usage of these features.
* The default sitemap protocol for sitemaps built outside the context of a
request is changed from ``'http'`` to ``'https'``.
* The ``extra_tests`` argument for ``DiscoverRunner.build_suite()`` and
``DiscoverRunner.run_tests()`` is removed.
See :ref:`deprecated-features-4.1` for details on these changes, including how
to remove usage of these features.

View File

@ -654,12 +654,6 @@ Methods
several formats (see :meth:`DiscoverRunner.build_suite` for a list of
supported formats).
.. deprecated:: 4.0
``extra_tests`` is a list of extra ``TestCase`` instances to add to the
suite that is executed by the test runner. These extra tests are run in
addition to those discovered in the modules listed in ``test_labels``.
This method should return the number of tests that failed.
.. classmethod:: DiscoverRunner.add_arguments(parser)
@ -695,12 +689,6 @@ Methods
tests in all files below the current directory whose names match its
``pattern`` (see above).
.. deprecated:: 4.0
``extra_tests`` is a list of extra ``TestCase`` instances to add to the
suite that is executed by the test runner. These extra tests are run in
addition to those discovered in the modules listed in ``test_labels``.
Returns a ``TestSuite`` instance ready to be run.
.. method:: DiscoverRunner.setup_databases(**kwargs)

View File

@ -31,7 +31,6 @@ from django.test.utils import (
get_unique_databases_and_mirrors,
iter_test_cases,
)
from django.utils.deprecation import RemovedInDjango50Warning
from .models import B, Person, Through
@ -1033,42 +1032,3 @@ class RunTestsExceptionHandlingTests(unittest.TestCase):
)
self.assertTrue(teardown_databases.called)
self.assertFalse(teardown_test_environment.called)
# RemovedInDjango50Warning
class NoOpTestRunner(DiscoverRunner):
def setup_test_environment(self, **kwargs):
return
def setup_databases(self, **kwargs):
return
def run_checks(self, databases):
return
def teardown_databases(self, old_config, **kwargs):
return
def teardown_test_environment(self, **kwargs):
return
class DiscoverRunnerExtraTestsDeprecationTests(SimpleTestCase):
msg = "The extra_tests argument is deprecated."
def get_runner(self):
return NoOpTestRunner(verbosity=0, interactive=False)
def test_extra_tests_build_suite(self):
runner = self.get_runner()
with self.assertWarnsMessage(RemovedInDjango50Warning, self.msg):
runner.build_suite(extra_tests=[])
def test_extra_tests_run_tests(self):
runner = self.get_runner()
with captured_stderr():
with self.assertWarnsMessage(RemovedInDjango50Warning, self.msg):
runner.run_tests(
test_labels=["test_runner_apps.sample.tests_sample.EmptyTestCase"],
extra_tests=[],
)