diff --git a/CHANGELOG b/CHANGELOG index be9dceeb..7937c851 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,11 @@ Unreleased ========== -- handle ``FileNotFoundError`` when trying to import pathlib in ``path.common`` +- Handle ``FileNotFoundError`` when trying to import pathlib in ``path.common`` on Python 3.4 (#207). +- ``py.path.local.samefile`` now works correctly in Python 3 on Windows when dealing with symlinks. + 1.8.0 (2019-02-21) ================== diff --git a/py/_path/local.py b/py/_path/local.py index 0e856a66..de6dcb4f 100644 --- a/py/_path/local.py +++ b/py/_path/local.py @@ -196,8 +196,8 @@ def samefile(self, other): other = abspath(other) if self == other: return True - if iswin32: - return False # there is no samefile + if not hasattr(os.path, "samefile"): + return False return py.error.checked_call( os.path.samefile, self.strpath, other) diff --git a/testing/path/test_local.py b/testing/path/test_local.py index 863157d6..ae009362 100644 --- a/testing/path/test_local.py +++ b/testing/path/test_local.py @@ -704,6 +704,17 @@ def test_samefile(tmpdir): p2 = p.__class__(str(p).upper()) assert p1.samefile(p2) +@pytest.mark.skipif(not hasattr(os, "symlink"), reason="os.symlink not available") +def test_samefile_symlink(tmpdir): + p1 = tmpdir.ensure("foo.txt") + p2 = tmpdir.join("linked.txt") + try: + os.symlink(str(p1), str(p2)) + except OSError as e: + # on Windows this might fail if the user doesn't have special symlink permissions + pytest.skip(str(e.args[0])) + + assert p1.samefile(p2) def test_listdir_single_arg(tmpdir): tmpdir.ensure("hello")