Refs #32532 -- Replaced is_discoverable() with try_importing().
This commit is contained in:
parent
e32722d160
commit
0af81b22b5
|
@ -595,7 +595,11 @@ class DiscoverRunner:
|
||||||
if tests.countTestCases():
|
if tests.countTestCases():
|
||||||
return tests
|
return tests
|
||||||
# Try discovery if "label" is a package or directory.
|
# Try discovery if "label" is a package or directory.
|
||||||
if not is_discoverable(label):
|
is_importable, is_package = try_importing(label)
|
||||||
|
if is_importable:
|
||||||
|
if not is_package:
|
||||||
|
return tests
|
||||||
|
elif not os.path.isdir(label_as_path):
|
||||||
return tests
|
return tests
|
||||||
|
|
||||||
kwargs = discover_kwargs.copy()
|
kwargs = discover_kwargs.copy()
|
||||||
|
@ -774,20 +778,18 @@ class DiscoverRunner:
|
||||||
return self.suite_result(suite, result)
|
return self.suite_result(suite, result)
|
||||||
|
|
||||||
|
|
||||||
def is_discoverable(label):
|
def try_importing(label):
|
||||||
"""
|
"""
|
||||||
Check if a test label points to a Python package or file directory.
|
Try importing a test label, and return (is_importable, is_package).
|
||||||
|
|
||||||
Relative labels like "." and ".." are seen as directories.
|
Relative labels like "." and ".." are seen as directories.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
mod = import_module(label)
|
mod = import_module(label)
|
||||||
except (ImportError, TypeError):
|
except (ImportError, TypeError):
|
||||||
pass
|
return (False, False)
|
||||||
else:
|
|
||||||
return hasattr(mod, '__path__')
|
|
||||||
|
|
||||||
return os.path.isdir(os.path.abspath(label))
|
return (True, hasattr(mod, '__path__'))
|
||||||
|
|
||||||
|
|
||||||
def find_top_level(top_level):
|
def find_top_level(top_level):
|
||||||
|
|
Loading…
Reference in New Issue