summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_support.py
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2009-03-30 23:05:48 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2009-03-30 23:05:48 (GMT)
commit3db8a3432bd84b58bdc7da2c9872777c537a4d09 (patch)
tree1a274c25cb002b9cb4474ff0882e2e5a563f9038 /Lib/test/test_support.py
parentdc340eedaa71bb6a86fd887a807020ccf1cbf520 (diff)
downloadcpython-3db8a3432bd84b58bdc7da2c9872777c537a4d09.zip
cpython-3db8a3432bd84b58bdc7da2c9872777c537a4d09.tar.gz
cpython-3db8a3432bd84b58bdc7da2c9872777c537a4d09.tar.bz2
Change more tests to use import_module for the modules that
should cause tests to be skipped. Also rename import_function to the more descriptive get_attribute and add a docstring.
Diffstat (limited to 'Lib/test/test_support.py')
-rw-r--r--Lib/test/test_support.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index 90bd8e6..4353339 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -12,6 +12,7 @@ import platform
import shutil
import warnings
import unittest
+import importlib
__all__ = ["Error", "TestFailed", "ResourceDenied", "import_module",
"verbose", "use_resources", "max_memuse", "record_original_stdout",
@@ -25,7 +26,7 @@ __all__ = ["Error", "TestFailed", "ResourceDenied", "import_module",
"run_with_locale", "set_memlimit", "bigmemtest", "bigaddrspacetest",
"BasicTestRunner", "run_unittest", "run_doctest", "threading_setup",
"threading_cleanup", "reap_children", "cpython_only",
- "check_impl_detail"]
+ "check_impl_detail", "get_attribute"]
class Error(Exception):
"""Base class for regression test exceptions."""
@@ -49,24 +50,26 @@ def import_module(name, deprecated=False):
warnings.filterwarnings("ignore", ".+ (module|package)",
DeprecationWarning)
try:
- module = __import__(name, level=0)
+ module = importlib.import_module(name)
except ImportError:
raise unittest.SkipTest("No module named " + name)
else:
return module
-def import_function(module, name, deprecated=False):
+def get_attribute(module, name, deprecated=False):
+ """Get an attribute from the module, raising SkipTest if it is
+ not available."""
with warnings.catch_warnings():
if deprecated:
warnings.filterwarnings("ignore", ".+ (module|package)",
DeprecationWarning)
try:
- function = getattr(module, name)
+ attribute = getattr(module, name)
except AttributeError:
- raise unittest.SkipTest("No function named %s in module %s" % (
- name, module.__name__))
+ raise unittest.SkipTest("module %s has no attribute %s" % (
+ module.__name__, name))
else:
- return function
+ return attribute
verbose = 1 # Flag set to 0 by regrtest.py