mirror of
https://github.com/python/cpython.git
synced 2025-07-29 22:24:49 +00:00
Improve test_support.import_module docstring, remove
deprecated flag from get_attribute since it isn't likely to do anything useful.
This commit is contained in:
parent
df90b02415
commit
bdeacba51b
1 changed files with 14 additions and 16 deletions
|
@ -43,8 +43,11 @@ class ResourceDenied(unittest.SkipTest):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def import_module(name, deprecated=False):
|
def import_module(name, deprecated=False):
|
||||||
"""Import the module to be tested, raising SkipTest if it is not
|
"""Import and return the module to be tested, raising SkipTest if
|
||||||
available."""
|
it is not available.
|
||||||
|
|
||||||
|
If deprecated is True, any module or package deprecation messages
|
||||||
|
will be suppressed."""
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
if deprecated:
|
if deprecated:
|
||||||
warnings.filterwarnings("ignore", ".+ (module|package)",
|
warnings.filterwarnings("ignore", ".+ (module|package)",
|
||||||
|
@ -56,20 +59,15 @@ def import_module(name, deprecated=False):
|
||||||
else:
|
else:
|
||||||
return module
|
return module
|
||||||
|
|
||||||
def get_attribute(module, name, deprecated=False):
|
def get_attribute(obj, name):
|
||||||
"""Get an attribute from the module, raising SkipTest if it is
|
"""Get an attribute, raising SkipTest if AttributeError is raised."""
|
||||||
not available."""
|
try:
|
||||||
with warnings.catch_warnings():
|
attribute = getattr(obj, name)
|
||||||
if deprecated:
|
except AttributeError:
|
||||||
warnings.filterwarnings("ignore", ".+ (module|package)",
|
raise unittest.SkipTest("module %s has no attribute %s" % (
|
||||||
DeprecationWarning)
|
obj.__name__, name))
|
||||||
try:
|
else:
|
||||||
attribute = getattr(module, name)
|
return attribute
|
||||||
except AttributeError:
|
|
||||||
raise unittest.SkipTest("module %s has no attribute %s" % (
|
|
||||||
module.__name__, name))
|
|
||||||
else:
|
|
||||||
return attribute
|
|
||||||
|
|
||||||
|
|
||||||
verbose = 1 # Flag set to 0 by regrtest.py
|
verbose = 1 # Flag set to 0 by regrtest.py
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue