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