Skip to content

'LocalPath.samefile' should normalize the path #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pytestbot opened this issue Sep 17, 2016 · 7 comments
Closed

'LocalPath.samefile' should normalize the path #58

pytestbot opened this issue Sep 17, 2016 · 7 comments

Comments

@pytestbot
Copy link

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)
@pytestbot
Copy link
Author

Original comment by @vladipus

I have created a PR with the change - https://bitbucket.org/pytest-dev/py/pull-request/28

@pytestbot
Copy link
Author

Original comment by @vladipus

Got this error once again, today. What kind of test are you looking for? The scenario is as that: install an MSys2 environment, Python and pytest. Then, try running the tests like::

if __name__ == '__main__':
  import pytest
  pytest.main()

The path on Windows should be normalized before comparing like that self == other, because a Windows path may use back slashes in its paths and are semantically equal to forward slashes.

Thank you.

@pytestbot
Copy link
Author

Original comment by @vladipus

Got no time for this currently. Maybe later. The fix is trivial and self-explanatory. I understand and respect your test-driven approach however.

@pytestbot
Copy link
Author

Original comment by @hpk42

can you submit a PR which includes a test that fails on windows?

@RonnyPfannschmidt
Copy link
Member

@rafaelpivato any interest in resuming this?

@blueyed
Copy link
Contributor

blueyed commented Sep 25, 2018

Is this still an issue?
The code has changed in this regard (e.g. ef37a06).

@RonnyPfannschmidt
Copy link
Member

i dont think its the same chagne

@RonnyPfannschmidt RonnyPfannschmidt closed this as not planned Won't fix, can't repro, duplicate, stale Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants