Apply suggestions from code review

Co-authored-by: Florian Bruhin <me@the-compiler.org>
This commit is contained in:
Bruno Oliveira 2024-04-25 17:57:04 -03:00 committed by GitHub
parent f14d78dbef
commit b59336ac47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View File

@ -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:

View File

@ -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:",