diff options
| author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2021-03-12 03:29:16 -0800 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-03-15 10:15:21 +0100 |
| commit | 7bdd09d016f418719f2d0297f58bd81c5349101d (patch) | |
| tree | 8f00468cb92b2fd9f8e920ffa5e6b1d98ecbae9a | |
| parent | d5a214c7c4575773e0f1b8b99f6018bcb7adb8cd (diff) | |
Fixed #32540 -- Optimized DiscoverRunner.build_suite() by calling find_top_level() only if is_discoverable() is true.
| -rw-r--r-- | django/test/runner.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/django/test/runner.py b/django/test/runner.py index b63ca6adb8..79cb296a20 100644 --- a/django/test/runner.py +++ b/django/test/runner.py @@ -565,20 +565,19 @@ class DiscoverRunner: all_tests = [] for label in test_labels: - kwargs = discover_kwargs.copy() - tests = None - label_as_path = os.path.abspath(label) + tests = None # if a module, or "module.ClassName[.method_name]", just run those if not os.path.exists(label_as_path): tests = self.test_loader.loadTestsFromName(label) - elif os.path.isdir(label_as_path) and not self.top_level: - top_level = find_top_level(label_as_path) - kwargs['top_level_dir'] = top_level + # Try discovery if "label" is a package or directory. if not (tests and tests.countTestCases()) and is_discoverable(label): - # Try discovery if path is a package or directory + kwargs = discover_kwargs.copy() + if os.path.isdir(label_as_path) and not self.top_level: + kwargs['top_level_dir'] = find_top_level(label_as_path) + tests = self.test_loader.discover(start_dir=label, **kwargs) # Make unittest forget the top-level dir it calculated from this |
