simvx.core.testing.optional¶
Guards for tests that need an optional package.
- func:
importlib.util.find_specis the obvious way to write “skip unless X is installed”, and it is wrong for any dotted name: it imports the parent package to read its__path__, so a missing parent raisesModuleNotFoundErrorinstead of returningNone.find_spec("simvx.physics.jolt")therefore answers “not installed” on a machine that hassimvx-physics-joltminus the submodule, and raises at collection time on one that has neither – which is every machine that installed only the engine.- func:
module_installedis the answer those guards actually want.
Module Contents¶
Functions¶
Return whether name can be imported, without importing it. |
Data¶
API¶
- simvx.core.testing.optional.__all__¶
[‘module_installed’]
- simvx.core.testing.optional.module_installed(name: str) bool[source]¶
Return whether name can be imported, without importing it.
Handles dotted names whose parent package is itself absent, and treats a parent that exists but fails to import as “not installed” rather than letting the import error escape into collection.
Args: name: A module name, dotted or not (
"pymunk","simvx.physics.jolt").Returns:
Truewhen the module can be located,Falseotherwise.