Allow providing a custom reason for `importorskip`
This commit is contained in:
parent
56aecfc081
commit
8b48621687
|
@ -137,7 +137,7 @@ def xfail(reason=""):
|
||||||
xfail.Exception = XFailed
|
xfail.Exception = XFailed
|
||||||
|
|
||||||
|
|
||||||
def importorskip(modname, minversion=None):
|
def importorskip(modname, minversion=None, reason=None):
|
||||||
""" return imported module if it has at least "minversion" as its
|
""" return imported module if it has at least "minversion" as its
|
||||||
__version__ attribute. If no minversion is specified the a skip
|
__version__ attribute. If no minversion is specified the a skip
|
||||||
is only triggered if the module can not be imported.
|
is only triggered if the module can not be imported.
|
||||||
|
@ -159,7 +159,9 @@ def importorskip(modname, minversion=None):
|
||||||
# Do not raise chained exception here(#1485)
|
# Do not raise chained exception here(#1485)
|
||||||
should_skip = True
|
should_skip = True
|
||||||
if should_skip:
|
if should_skip:
|
||||||
raise Skipped("could not import %r" % (modname,), allow_module_level=True)
|
if reason is None:
|
||||||
|
reason = "could not import %r" % (modname,)
|
||||||
|
raise Skipped(reason, allow_module_level=True)
|
||||||
mod = sys.modules[modname]
|
mod = sys.modules[modname]
|
||||||
if minversion is None:
|
if minversion is None:
|
||||||
return mod
|
return mod
|
||||||
|
|
Loading…
Reference in New Issue