Added warning and Test Cases
This commit is contained in:
parent
543262c4c8
commit
9a9643d29e
|
@ -232,20 +232,25 @@ def importorskip(
|
|||
warnings.simplefilter("ignore")
|
||||
|
||||
if exc_type is None:
|
||||
exc_type = ModuleNotFoundError
|
||||
else:
|
||||
exc_type = ImportError
|
||||
warnings.warn(
|
||||
PytestDeprecationWarning(
|
||||
"The Default behaviour will change to ImportError in future",
|
||||
)
|
||||
)
|
||||
warn_on_import_error = True
|
||||
else:
|
||||
warn_on_import_error = False
|
||||
|
||||
try:
|
||||
__import__(modname)
|
||||
except exc_type as exc:
|
||||
if reason is None:
|
||||
reason = f"could not import {modname!r}: {exc}"
|
||||
if warn_on_import_error and type(exc) is ImportError:
|
||||
warnings.warn(
|
||||
PytestDeprecationWarning(
|
||||
f"""pytest.importorskip() caught {exc},but this will change in a future pytest release
|
||||
to only capture ModuleNotFoundError exceptions by default.\nTo overwrite the future
|
||||
behavior and silence this warning, pass exc_type=ImportError explicitly."""
|
||||
)
|
||||
)
|
||||
|
||||
raise Skipped(reason, allow_module_level=True) from None
|
||||
|
||||
mod = sys.modules[modname]
|
||||
|
|
|
@ -774,7 +774,12 @@ def test_importorskip_importError_warning(pytester: Pytester) -> None:
|
|||
|
||||
with pytest.raises(pytest.skip.Exception):
|
||||
with pytest.warns(PytestDeprecationWarning):
|
||||
pytest.importorskip(fn.stem, exc_type=ImportError)
|
||||
pytest.importorskip(fn.stem)
|
||||
|
||||
|
||||
def test_importorskip_ModuleNotFoundError() -> None:
|
||||
with pytest.raises(pytest.skip.Exception):
|
||||
pytest.importorskip("abcdefgh")
|
||||
|
||||
|
||||
def test_importorskip_dev_module(monkeypatch) -> None:
|
||||
|
|
Loading…
Reference in New Issue