Skip to content

Commit

Permalink
gh-11523: add importorskip(exc=...) kwarg
Browse files Browse the repository at this point in the history
Fixes #11523
  • Loading branch information
graingert authored Oct 19, 2023
1 parent cdddd6d commit dc2080f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/_pytest/outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ def xfail(reason: str = "") -> NoReturn:


def importorskip(
modname: str, minversion: Optional[str] = None, reason: Optional[str] = None
modname: str, minversion: Optional[str] = None, reason: Optional[str] = None,
exc: type[ImportError] = ImportError,
) -> Any:
"""Import and return the requested module ``modname``, or skip the
current test if the module cannot be imported.
Expand Down Expand Up @@ -282,9 +283,9 @@ def importorskip(
warnings.simplefilter("ignore")
try:
__import__(modname)
except ImportError as exc:
except exc as e:
if reason is None:
reason = f"could not import {modname!r}: {exc}"
reason = f"could not import {modname!r}: {e}"
raise Skipped(reason, allow_module_level=True) from None
mod = sys.modules[modname]
if minversion is None:
Expand Down

0 comments on commit dc2080f

Please sign in to comment.