(monkeypatch)
| 696 | |
| 697 | |
| 698 | def test_importorskip(monkeypatch) -> None: |
| 699 | importorskip = pytest.importorskip |
| 700 | |
| 701 | def f(): |
| 702 | importorskip("asdlkj") |
| 703 | |
| 704 | try: |
| 705 | sysmod = importorskip("sys") |
| 706 | assert sysmod is sys |
| 707 | # path = pytest.importorskip("os.path") |
| 708 | # assert path == os.path |
| 709 | excinfo = pytest.raises(pytest.skip.Exception, f) |
| 710 | assert excinfo is not None |
| 711 | excrepr = excinfo.getrepr() |
| 712 | assert excrepr is not None |
| 713 | assert excrepr.reprcrash is not None |
| 714 | path = Path(excrepr.reprcrash.path) |
| 715 | # check that importorskip reports the actual call |
| 716 | # in this test the test_runner.py file |
| 717 | assert path.stem == "test_runner" |
| 718 | pytest.raises(SyntaxError, pytest.importorskip, "x y z") |
| 719 | pytest.raises(SyntaxError, pytest.importorskip, "x=y") |
| 720 | mod = types.ModuleType("hello123") |
| 721 | mod.__version__ = "1.3" # type: ignore |
| 722 | monkeypatch.setitem(sys.modules, "hello123", mod) |
| 723 | with pytest.raises(pytest.skip.Exception): |
| 724 | pytest.importorskip("hello123", minversion="1.3.1") |
| 725 | mod2 = pytest.importorskip("hello123", minversion="1.3") |
| 726 | assert mod2 == mod |
| 727 | except pytest.skip.Exception: # pragma: no cover |
| 728 | assert False, f"spurious skip: {ExceptionInfo.from_current()}" |
| 729 | |
| 730 | |
| 731 | def test_importorskip_imports_last_module_part() -> None: |
nothing calls this directly
no test coverage detected