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=())
| 79 | |
| 80 | |
| 81 | def import_module(name, deprecated=False, *, required_on=()): |
| 82 | """Import and return the module to be tested, raising SkipTest if |
| 83 | it is not available. |
| 84 | |
| 85 | If deprecated is True, any module or package deprecation messages |
| 86 | will be suppressed. If a module is required on a platform but optional for |
| 87 | others, set required_on to an iterable of platform prefixes which will be |
| 88 | compared against sys.platform. |
| 89 | """ |
| 90 | with _ignore_deprecated_imports(deprecated): |
| 91 | try: |
| 92 | return importlib.import_module(name) |
| 93 | except ImportError as msg: |
| 94 | if sys.platform.startswith(tuple(required_on)): |
| 95 | raise |
| 96 | raise unittest.SkipTest(str(msg)) |
| 97 | |
| 98 | |
| 99 | def _save_and_remove_modules(names): |
searching dependent graphs…