summaryrefslogtreecommitdiffstats
path: root/Lib/test/support.py
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2009-03-31 23:16:50 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2009-03-31 23:16:50 (GMT)
commita21e4ca3c6dc00b2825e2bb4e77a4aa76d8485f0 (patch)
tree6f6ce1531ec759058bf6390b5831b8dcc8c0cea0 /Lib/test/support.py
parenta1b49013f477e83bd1652f651f35c2e4eea54b67 (diff)
downloadcpython-a21e4ca3c6dc00b2825e2bb4e77a4aa76d8485f0.zip
cpython-a21e4ca3c6dc00b2825e2bb4e77a4aa76d8485f0.tar.gz
cpython-a21e4ca3c6dc00b2825e2bb4e77a4aa76d8485f0.tar.bz2
Merged revisions 70734,70775,70856,70874,70876-70877 via svnmerge
........ r70734 | r.david.murray | 2009-03-30 15:04:00 -0400 (Mon, 30 Mar 2009) | 7 lines Add import_function method to test.test_support, and modify a number of tests that expect to be skipped if imports fail or functions don't exist to use import_function and import_module. The ultimate goal is to change regrtest to not skip automatically on ImportError. Checking in now to make sure the buldbots don't show any errors on platforms I can't direct test on. ........ r70775 | r.david.murray | 2009-03-30 19:05:48 -0400 (Mon, 30 Mar 2009) | 4 lines 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. ........ r70856 | r.david.murray | 2009-03-31 14:32:17 -0400 (Tue, 31 Mar 2009) | 7 lines A few more test skips via import_module, and change import_module to return the error message produced by importlib, so that if an import in the package whose import is being wrapped is what failed the skip message will contain the name of that module instead of the name of the wrapped module. Also fixed formatting of some previous comments. ........ r70874 | r.david.murray | 2009-03-31 15:33:15 -0400 (Tue, 31 Mar 2009) | 5 lines Improve test_support.import_module docstring, remove deprecated flag from get_attribute since it isn't likely to do anything useful. ........ r70876 | r.david.murray | 2009-03-31 15:49:15 -0400 (Tue, 31 Mar 2009) | 4 lines Remove the regrtest check that turns any ImportError into a skipped test. Hopefully all modules whose imports legitimately result in a skipped test have been properly wrapped by the previous commits. ........ r70877 | r.david.murray | 2009-03-31 15:57:24 -0400 (Tue, 31 Mar 2009) | 2 lines Add NEWS entry for regrtest change. ........
Diffstat (limited to 'Lib/test/support.py')
-rw-r--r--Lib/test/support.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py
index e209170..9cd50a0 100644
--- a/Lib/test/support.py
+++ b/Lib/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",
@@ -24,7 +25,7 @@ __all__ = ["Error", "TestFailed", "ResourceDenied", "import_module",
"TransientResource", "transient_internet", "run_with_locale",
"set_memlimit", "bigmemtest", "bigaddrspacetest", "BasicTestRunner",
"run_unittest", "run_doctest", "threading_setup", "threading_cleanup",
- "reap_children", "cpython_only", "check_impl_detail"]
+ "reap_children", "cpython_only", "check_impl_detail", "get_attribute"]
class Error(Exception):
"""Base class for regression test exceptions."""
@@ -41,19 +42,32 @@ class ResourceDenied(unittest.SkipTest):
"""
def import_module(name, deprecated=False):
- """Import the module to be tested, raising SkipTest if it is not
- available."""
+ """Import and return the module to be tested, raising SkipTest if
+ it is not available.
+
+ If deprecated is True, any module or package deprecation messages
+ will be suppressed."""
with warnings.catch_warnings():
if deprecated:
warnings.filterwarnings("ignore", ".+ (module|package)",
DeprecationWarning)
try:
- module = __import__(name, level=0)
- except ImportError:
- raise unittest.SkipTest("No module named " + name)
+ module = importlib.import_module(name)
+ except ImportError as msg:
+ raise unittest.SkipTest(str(msg))
else:
return module
+def get_attribute(obj, name):
+ """Get an attribute, raising SkipTest if AttributeError is raised."""
+ try:
+ attribute = getattr(obj, name)
+ except AttributeError:
+ raise unittest.SkipTest("module %s has no attribute %s" % (
+ obj.__name__, name))
+ else:
+ return attribute
+
verbose = 1 # Flag set to 0 by regrtest.py
use_resources = None # Flag set to [] by regrtest.py
max_memuse = 0 # Disable bigmem tests (they will still be run with