2
0
Эх сурвалжийг харах

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

Chris Jerdonek 4 жил өмнө
parent
commit
a89e975caf

+ 7 - 0
django/test/runner.py

@@ -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()

+ 10 - 0
tests/test_runner/test_discover_runner.py

@@ -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'],