(monkeypatch)
| 792 | |
| 793 | |
| 794 | def test_importorskip(monkeypatch) -> None: |
| 795 | importorskip = pytest.importorskip |
| 796 | |
| 797 | def f(): |
| 798 | importorskip("asdlkj") |
| 799 | |
| 800 | try: |
| 801 | sysmod = importorskip("sys") |
| 802 | assert sysmod is sys |
| 803 | # path = pytest.importorskip("os.path") |
| 804 | # assert path == os.path |
| 805 | excinfo = pytest.raises(pytest.skip.Exception, f) |
| 806 | assert excinfo is not None |
| 807 | excrepr = excinfo.getrepr() |
| 808 | assert excrepr is not None |
| 809 | assert excrepr.reprcrash is not None |
| 810 | path = Path(excrepr.reprcrash.path) |
| 811 | # check that importorskip reports the actual call |
| 812 | # in this test the test_runner.py file |
| 813 | assert path.stem == "test_runner" |
| 814 | with pytest.raises(SyntaxError): |
| 815 | pytest.importorskip("x y z") |
| 816 | with pytest.raises(SyntaxError): |
| 817 | pytest.importorskip("x=y") |
| 818 | mod = types.ModuleType("hello123") |
| 819 | mod.__version__ = "1.3" # type: ignore |
| 820 | monkeypatch.setitem(sys.modules, "hello123", mod) |
| 821 | with pytest.raises(pytest.skip.Exception): |
| 822 | pytest.importorskip("hello123", minversion="1.3.1") |
| 823 | mod2 = pytest.importorskip("hello123", minversion="1.3") |
| 824 | assert mod2 == mod |
| 825 | except pytest.skip.Exception: # pragma: no cover |
| 826 | assert False, f"spurious skip: {ExceptionInfo.from_current()}" |
| 827 | |
| 828 | |
| 829 | def test_importorskip_imports_last_module_part() -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…