diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index 9b5a80e95..5ac93f151 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -37,7 +37,7 @@ error so the underlying issue can be fixed. In ``8.2`` the ``exc_type`` parameter has been added, giving users the ability of passing :class:`ModuleNotFoundError` to skip tests only if the module cannot really be found, and not because of some other error. -Catching only :class:`ModuleNotFoundError` by default (and let other errors propagate) would be the best solution, +Catching only :class:`ModuleNotFoundError` by default (and letting other errors propagate) would be the best solution, however for backward compatibility, pytest will keep the existing behavior but raise an warning if: 1. The captured exception is of type :class:`ImportError`, and: diff --git a/src/_pytest/outcomes.py b/src/_pytest/outcomes.py index 698222725..8749141aa 100644 --- a/src/_pytest/outcomes.py +++ b/src/_pytest/outcomes.py @@ -269,7 +269,7 @@ def importorskip( reason = f"could not import {modname!r}: {exc}" skipped = Skipped(reason, allow_module_level=True) - if warn_on_import_error and type(exc) is ImportError: + if warn_on_import_error and not issubclass(exc, ModuleNotFoundError): lines = [ "", f"Module '{modname}' was found, but when imported by pytest it raised:",