1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #32532 -- Made DiscoverRunner raise RuntimeError when a test label is a file path.

This commit is contained in:
Chris Jerdonek 2021-03-24 05:54:21 -07:00 committed by Mariusz Felisiak
parent 0af81b22b5
commit a89e975caf
2 changed files with 17 additions and 0 deletions

View File

@ -600,6 +600,13 @@ class DiscoverRunner:
if not is_package:
return tests
elif not os.path.isdir(label_as_path):
if os.path.exists(label_as_path):
assert tests is None
raise RuntimeError(
f'One of the test labels is a path to a file: {label!r}, '
f'which is not supported. Use a dotted module name '
f'instead.'
)
return tests
kwargs = discover_kwargs.copy()

View File

@ -47,6 +47,16 @@ class DiscoverRunnerTests(SimpleTestCase):
ns = parser.parse_args(["--debug-mode"])
self.assertTrue(ns.debug_mode)
def test_load_tests_for_label_file_path(self):
with change_cwd('.'):
msg = (
"One of the test labels is a path to a file: "
"'test_discover_runner.py', which is not supported. Use a "
"dotted module name instead."
)
with self.assertRaisesMessage(RuntimeError, msg):
DiscoverRunner().load_tests_for_label('test_discover_runner.py', {})
def test_dotted_test_module(self):
count = DiscoverRunner().build_suite(
['test_runner_apps.sample.tests_sample'],