import_file() should not raise ImportPathMismatchError if the paths are exactly equal on Windows. It seems directories mounted as UNC paths make os.path.samefile return False, even when they are clearly equal.
(tmp_path: Path, monkeypatch: MonkeyPatch)
| 431 | |
| 432 | @pytest.mark.skipif(not sys.platform.startswith("win"), reason="Windows only") |
| 433 | def test_samefile_false_negatives(tmp_path: Path, monkeypatch: MonkeyPatch) -> None: |
| 434 | """ |
| 435 | import_file() should not raise ImportPathMismatchError if the paths are exactly |
| 436 | equal on Windows. It seems directories mounted as UNC paths make os.path.samefile |
| 437 | return False, even when they are clearly equal. |
| 438 | """ |
| 439 | module_path = tmp_path.joinpath("my_module.py") |
| 440 | module_path.write_text("def foo(): return 42") |
| 441 | monkeypatch.syspath_prepend(tmp_path) |
| 442 | |
| 443 | with monkeypatch.context() as mp: |
| 444 | # Forcibly make os.path.samefile() return False here to ensure we are comparing |
| 445 | # the paths too. Using a context to narrow the patch as much as possible given |
| 446 | # this is an important system function. |
| 447 | mp.setattr(os.path, "samefile", lambda x, y: False) |
| 448 | module = import_path(module_path, root=tmp_path) |
| 449 | assert getattr(module, "foo")() == 42 |
| 450 | |
| 451 | |
| 452 | class TestImportLibMode: |
nothing calls this directly
no test coverage detected