summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2020-12-13 10:35:11 -0300
committerGitHub <noreply@github.com>2020-12-13 10:35:11 -0300
commit7e2e6630adf6889d0481e58ec4e3339bfa4db7b5 (patch)
tree2538fd68205e2501c99d1b9d6f758feba1b03845 /testing
parentfa784e1436394fe3a5c332c1aa14e7715ca6c77a (diff)
parent572dfcd160299489e66454de89a608da6f6d468e (diff)
downloadpytest-7e2e6630adf6889d0481e58ec4e3339bfa4db7b5.tar.gz
Merge pull request #8123 from nicoddemus/import-mismatch-unc
Compare also paths on Windows when considering ImportPathMismatchError
Diffstat (limited to 'testing')
-rw-r--r--testing/test_pathlib.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/testing/test_pathlib.py b/testing/test_pathlib.py
index 0507e3d68..f60b9f263 100644
--- a/testing/test_pathlib.py
+++ b/testing/test_pathlib.py
@@ -7,6 +7,7 @@ from textwrap import dedent
import py
import pytest
+from _pytest.monkeypatch import MonkeyPatch
from _pytest.pathlib import bestrelpath
from _pytest.pathlib import commonpath
from _pytest.pathlib import ensure_deletable
@@ -414,3 +415,23 @@ def test_visit_ignores_errors(tmpdir) -> None:
"bar",
"foo",
]
+
+
+@pytest.mark.skipif(not sys.platform.startswith("win"), reason="Windows only")
+def test_samefile_false_negatives(tmp_path: Path, monkeypatch: MonkeyPatch) -> None:
+ """
+ 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.
+ """
+ module_path = tmp_path.joinpath("my_module.py")
+ module_path.write_text("def foo(): return 42")
+ monkeypatch.syspath_prepend(tmp_path)
+
+ with monkeypatch.context() as mp:
+ # Forcibly make os.path.samefile() return False here to ensure we are comparing
+ # the paths too. Using a context to narrow the patch as much as possible given
+ # this is an important system function.
+ mp.setattr(os.path, "samefile", lambda x, y: False)
+ module = import_path(module_path)
+ assert getattr(module, "foo")() == 42