mirror of
https://github.com/django/django.git
synced 2025-03-13 10:50:55 +00:00
Refs #32655 -- Removed extra_tests argument for DiscoverRunner.build_suite()/run_tests().
Per deprecation timeline.
This commit is contained in:
parent
4eb97a90f0
commit
43b01300b7
@ -11,7 +11,6 @@ import random
|
|||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from importlib import import_module
|
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.test.utils import teardown_test_environment
|
||||||
from django.utils.crypto import new_hash
|
from django.utils.crypto import new_hash
|
||||||
from django.utils.datastructures import OrderedSet
|
from django.utils.datastructures import OrderedSet
|
||||||
from django.utils.deprecation import RemovedInDjango50Warning
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import ipdb as pdb
|
import ipdb as pdb
|
||||||
@ -877,15 +875,8 @@ class DiscoverRunner:
|
|||||||
self.test_loader._top_level_dir = None
|
self.test_loader._top_level_dir = None
|
||||||
return tests
|
return tests
|
||||||
|
|
||||||
def build_suite(self, test_labels=None, extra_tests=None, **kwargs):
|
def build_suite(self, test_labels=None, **kwargs):
|
||||||
if extra_tests is not None:
|
|
||||||
warnings.warn(
|
|
||||||
"The extra_tests argument is deprecated.",
|
|
||||||
RemovedInDjango50Warning,
|
|
||||||
stacklevel=2,
|
|
||||||
)
|
|
||||||
test_labels = test_labels or ["."]
|
test_labels = test_labels or ["."]
|
||||||
extra_tests = extra_tests or []
|
|
||||||
|
|
||||||
discover_kwargs = {}
|
discover_kwargs = {}
|
||||||
if self.pattern is not None:
|
if self.pattern is not None:
|
||||||
@ -899,8 +890,6 @@ class DiscoverRunner:
|
|||||||
tests = self.load_tests_for_label(label, discover_kwargs)
|
tests = self.load_tests_for_label(label, discover_kwargs)
|
||||||
all_tests.extend(iter_test_cases(tests))
|
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 or self.exclude_tags:
|
||||||
if self.tags:
|
if self.tags:
|
||||||
self.log(
|
self.log(
|
||||||
@ -1030,7 +1019,7 @@ class DiscoverRunner:
|
|||||||
)
|
)
|
||||||
return databases
|
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.
|
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.
|
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()
|
self.setup_test_environment()
|
||||||
suite = self.build_suite(test_labels, extra_tests)
|
suite = self.build_suite(test_labels)
|
||||||
databases = self.get_databases(suite)
|
databases = self.get_databases(suite)
|
||||||
suite.serialized_aliases = set(
|
suite.serialized_aliases = set(
|
||||||
alias for alias, serialize in databases.items() if serialize
|
alias for alias, serialize in databases.items() if serialize
|
||||||
|
@ -267,6 +267,9 @@ to remove usage of these features.
|
|||||||
* The default sitemap protocol for sitemaps built outside the context of a
|
* The default sitemap protocol for sitemaps built outside the context of a
|
||||||
request is changed from ``'http'`` to ``'https'``.
|
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
|
See :ref:`deprecated-features-4.1` for details on these changes, including how
|
||||||
to remove usage of these features.
|
to remove usage of these features.
|
||||||
|
|
||||||
|
@ -654,12 +654,6 @@ Methods
|
|||||||
several formats (see :meth:`DiscoverRunner.build_suite` for a list of
|
several formats (see :meth:`DiscoverRunner.build_suite` for a list of
|
||||||
supported formats).
|
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.
|
This method should return the number of tests that failed.
|
||||||
|
|
||||||
.. classmethod:: DiscoverRunner.add_arguments(parser)
|
.. classmethod:: DiscoverRunner.add_arguments(parser)
|
||||||
@ -695,12 +689,6 @@ Methods
|
|||||||
tests in all files below the current directory whose names match its
|
tests in all files below the current directory whose names match its
|
||||||
``pattern`` (see above).
|
``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.
|
Returns a ``TestSuite`` instance ready to be run.
|
||||||
|
|
||||||
.. method:: DiscoverRunner.setup_databases(**kwargs)
|
.. method:: DiscoverRunner.setup_databases(**kwargs)
|
||||||
|
@ -31,7 +31,6 @@ from django.test.utils import (
|
|||||||
get_unique_databases_and_mirrors,
|
get_unique_databases_and_mirrors,
|
||||||
iter_test_cases,
|
iter_test_cases,
|
||||||
)
|
)
|
||||||
from django.utils.deprecation import RemovedInDjango50Warning
|
|
||||||
|
|
||||||
from .models import B, Person, Through
|
from .models import B, Person, Through
|
||||||
|
|
||||||
@ -1033,42 +1032,3 @@ class RunTestsExceptionHandlingTests(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertTrue(teardown_databases.called)
|
self.assertTrue(teardown_databases.called)
|
||||||
self.assertFalse(teardown_test_environment.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=[],
|
|
||||||
)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user