Skip to content

'LocalPath.samefile' should normalize the path #58

Closed as not planned
Closed as not planned
@pytestbot

Description

@pytestbot

The 'LocalPath.samefile' method should normalize the path on MS Windows, since it can contain back slahes.
Otherwise, I'm getting the following error in (my currently loved of which I'm thankful to you) pytest system:

Traceback (most recent call last):
File "C:\msys64\mingw64\lib\python2.7\site-packages/_pytest/config.py", line 543, in importconftest
mod = conftestpath.pyimport()
File "C:\msys64\mingw64\lib\python2.7\site-packages\py/_path/local.py", line 664, in pyimport
  raise self.ImportMismatchError(modname, modfile, self)
ImportMismatchError: ('conftest', 'C:\\secret-project\\tests/conftest.py', local('C:\\secret-project\\tests\\conftest.py'))

Suggested fix:

def samefile(self, other):
    """ return True if 'other' references the same file as 'self'.
    """
    other = getattr(other, "strpath", other)
    if not isabs(other):
        other = abspath(other)
    if self == other:
        return True
    if iswin32:
        # Convert possible forward slashes to back.
        if self == normpath(other):
            return True
        else:
            return False # there is no samefile
    return py.error.checked_call(
            os.path.samefile, self.strpath, other)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions