1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

Fixed #21206 -- No longer run discovery if the test label doesn't point to a package or directory.

Thanks thepapermen for the report and Carl Meyer for the review.
This commit is contained in:
Preston Timmons
2013-12-16 10:04:28 -06:00
committed by Tim Graham
parent 52325b0a04
commit aef019de61
4 changed files with 50 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
from importlib import import_module
import os
from optparse import make_option
import unittest
@@ -89,11 +90,11 @@ class DiscoverRunner(object):
break
kwargs['top_level_dir'] = top_level
if not (tests and tests.countTestCases()):
# if no tests found, it's probably a package; try discovery
if not (tests and tests.countTestCases()) and is_discoverable(label):
# Try discovery if path is a package or directory
tests = self.test_loader.discover(start_dir=label, **kwargs)
# make unittest forget the top-level dir it calculated from this
# Make unittest forget the top-level dir it calculated from this
# run, to support running tests from two different top-levels.
self.test_loader._top_level_dir = None
@@ -150,6 +151,20 @@ class DiscoverRunner(object):
return self.suite_result(suite, result)
def is_discoverable(label):
"""
Check if a test label points to a python package or file directory.
"""
try:
mod = import_module(label)
except ImportError:
pass
else:
return hasattr(mod, '__path__')
return os.path.isdir(os.path.abspath(label))
def dependency_ordered(test_databases, dependencies):
"""
Reorder test_databases into an order that honors the dependencies