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. If a module is required on a platform but optional for others, set required_on to an iterable of platform prefixe
(name, deprecated=False, *, required_on=())
| 67 | |
| 68 | |
| 69 | def import_module(name, deprecated=False, *, required_on=()): |
| 70 | """Import and return the module to be tested, raising SkipTest if |
| 71 | it is not available. |
| 72 | |
| 73 | If deprecated is True, any module or package deprecation messages |
| 74 | will be suppressed. If a module is required on a platform but optional for |
| 75 | others, set required_on to an iterable of platform prefixes which will be |
| 76 | compared against sys.platform. |
| 77 | """ |
| 78 | with _ignore_deprecated_imports(deprecated): |
| 79 | try: |
| 80 | return importlib.import_module(name) |
| 81 | except ImportError as msg: |
| 82 | if sys.platform.startswith(tuple(required_on)): |
| 83 | raise |
| 84 | raise unittest.SkipTest(str(msg)) |
| 85 | |
| 86 | |
| 87 | def _save_and_remove_modules(names): |