mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
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.
This commit is contained in:
parent
8f1fefab9a
commit
d187726504
4 changed files with 14 additions and 298 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue