summaryrefslogtreecommitdiffstats
path: root/Lib/test/support.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2012-11-18 01:46:26 (GMT)
committerBrett Cannon <brett@python.org>2012-11-18 01:46:26 (GMT)
commitd18772650465b5a04e1fd1439c13ffc152666703 (patch)
tree407db06b4189b0db2bedafe8879e91ba428edb6e /Lib/test/support.py
parent8f1fefab9a0816dd9fb089a7a0398e195a8e4b97 (diff)
downloadcpython-d18772650465b5a04e1fd1439c13ffc152666703.zip
cpython-d18772650465b5a04e1fd1439c13ffc152666703.tar.gz
cpython-d18772650465b5a04e1fd1439c13ffc152666703.tar.bz2
Issue #10966: Remove the concept of unexpected skipped tests.
The concept of what was unexpected was typically defined as "some depencendy wasn't installed", which isn't unexpected at all as it's totally optional. Since it confuses new contributors as they think something is wrong with their installation it seems sensible to get rid of the concept. This change also adds the concept of optional tests that are required to work on a specific platform(s) (e.g. test_winreg on Windows). This should help catch compile issues instead of a test being blindly skipped even when it should have run. The skipped test list in the future can also print out the reason for being skipped to make it more obvious as to why the skipping occurred.
Diffstat (limited to 'Lib/test/support.py')
-rw-r--r--Lib/test/support.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py
index d0a37ea..9c01cae 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -93,7 +93,8 @@ def _ignore_deprecated_imports(ignore=True):
"""Context manager to suppress package and module deprecation
warnings when importing them.
- If ignore is False, this context manager has no effect."""
+ If ignore is False, this context manager has no effect.
+ """
if ignore:
with warnings.catch_warnings():
warnings.filterwarnings("ignore", ".+ (module|package)",
@@ -103,23 +104,29 @@ def _ignore_deprecated_imports(ignore=True):
yield
-def import_module(name, deprecated=False):
+def import_module(name, deprecated=False, *, required_on=()):
"""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."""
+ will be suppressed. If a module is required on a platform but optional for
+ others, set required_on to an iterable of platform prefixes which will be
+ compared against sys.platform.
+ """
with _ignore_deprecated_imports(deprecated):
try:
return importlib.import_module(name)
except ImportError as msg:
+ if sys.platform.startswith(tuple(required_on)):
+ raise
raise unittest.SkipTest(str(msg))
def _save_and_remove_module(name, orig_modules):
"""Helper function to save and remove a module from sys.modules
- Raise ImportError if the module can't be imported."""
+ Raise ImportError if the module can't be imported.
+ """
# try to import the module and raise an error if it can't be imported
if name not in sys.modules:
__import__(name)