Skip to content
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

ImportPathMismatchError on WindowsPath #8076

Closed
jaraco opened this issue Nov 26, 2020 · 4 comments · Fixed by #8123
Closed

ImportPathMismatchError on WindowsPath #8076

jaraco opened this issue Nov 26, 2020 · 4 comments · Fixed by #8123
Labels
closed as duplicate Issue is a duplicate of another issue platform: windows windows platform-specific problem type: bug problem that needs to be addressed

Comments

@jaraco
Copy link
Contributor

jaraco commented Nov 26, 2020

I'm running pytest in a Windows 2019 Docker image on macOS 11 with the project under test mounted from the host file system at C:\src.

When I run pytest under tox the first time, the tests run as expected.

When I run them a second time, pytest fails early with an ImportError:

PS C:\src> tox -- -k test_ls --pdb
GLOB sdist-make: C:\src\setup.py
python inst-nodeps: C:\tox\.tmp\package\1\cmdix-0.2.1.dev87+gd3e3450.d20201126.zip
python installed: appdirs==1.4.4,atomicwrites==1.4.0,attrs==20.3.0,black==20.8b1,click==7.1.2,cmdix @ file:///C:/tox/.tmp/package/1/cmdix-0.2.1.dev87%2Bgd3e3450.d20201126.zip,colorama==0.4.4,coverage==5.3,docutils==0.16,filelock==3.0.12,flake8==3.8.4,importlib-metadata==3.1.0,importlib-resources==3.3.0,iniconfig==1.1.1,jaraco.apt==2.0,jaraco.classes==3.1.0,jaraco.collections==3.0.0,jaraco.context==3.0.0,jaraco.functools==3.0.1,jaraco.test==4.0.1,jaraco.text==3.2.0,mccabe==0.6.1,more-itertools==8.6.0,mypy==0.790,mypy-extensions==0.4.3,packaging==20.4,pathspec==0.8.1,pluggy==0.13.1,py==1.9.0,pycodestyle==2.6.0,pyflakes==2.2.0,pyparsing==2.4.7,pytest==6.1.2,pytest-black==0.3.12,pytest-checkdocs==2.1.1,pytest-cov==2.10.1,pytest-flake8==1.0.6,pytest-mypy==0.8.0,pytz==2020.4,regex==2020.11.13,six==1.15.0,tempora==4.0.1,toml==0.10.2,typed-ast==1.4.1,typing-extensions==3.7.4.3,yg.lockfile==2.3,zc.lockfile==2.0,zipp==3.4.0
python run-test-pre: PYTHONHASHSEED='641'
python run-test: commands[0] | pytest -k test_ls --pdb
ImportError while loading conftest 'C:\src\conftest.py'.
_pytest.pathlib.ImportPathMismatchError: ('conftest', 'C:\\src\\conftest.py', WindowsPath('C:/src/conftest.py'))
ERROR: InvocationError for command 'C:\tox\python\Scripts\pytest.EXE' -k test_ls --pdb (exited with code 4)
_____________________________________________________________ summary _____________________________________________________________ 
ERROR:   python: commands failed

It appears that pytest is somehow detecting that C:\src\conftest.py is not the same file as C:/src/conftest.py. I'm not sure what library is generating the wrong slashes.

Deleting the tox work dir at C:\tox and re-running tox allows the tests to run once again, so whatever is caching path with the funny slashes is caching it in the tox work dir.

@Zac-HD Zac-HD added platform: windows windows platform-specific problem type: bug problem that needs to be addressed labels Nov 27, 2020
@nicoddemus
Copy link
Member

Hi @jaraco,

Sorry for the delay.

Seems that the problem is not really the forward/backward slashes:

>>> import os.path
>>> os.path.samefile('d:\\projects', 'd:/projects')
True

(That exception is raised when that samefile call returns False).

I suspect it is the same problem as in #7678.

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Dec 12, 2020
On Windows, os.path.samefile returns false for paths mounted in UNC paths which
point to the same location.

I couldn't reproduce the actual case reported, but looking at the code it seems
this commit should fix the issue.

Fix pytest-dev#7678
Fix pytest-dev#8076
nicoddemus added a commit to nicoddemus/pytest that referenced this issue Dec 12, 2020
On Windows, os.path.samefile returns false for paths mounted in UNC paths which
point to the same location.

I couldn't reproduce the actual case reported, but looking at the code it seems
this commit should fix the issue.

Fix pytest-dev#7678
Fix pytest-dev#8076
@jaraco
Copy link
Contributor Author

jaraco commented Dec 12, 2020

Agreed these issues are very similar. It's not a UNC path, but it is a mounted path, so likely going through similar underlying APIs that may be failing on samefile. I'll try with your branch and see how it goes.

@jaraco
Copy link
Contributor Author

jaraco commented Dec 12, 2020

I've confirmed the issue was still occurring on pytest stable, then remedied by using the candidate commit above. I was careful to run the tox tests twice in each configuration (because the issue only occurred on subsequent invocations) and clean between the two experiments.

So I'm pleased to say this issue is a confirmed duplicate and the proposed fix works as intended.

@jaraco jaraco closed this as completed Dec 12, 2020
@jaraco jaraco added the closed as duplicate Issue is a duplicate of another issue label Dec 12, 2020
@nicoddemus
Copy link
Member

Awesome, thanks for testing it out @jaraco. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed as duplicate Issue is a duplicate of another issue platform: windows windows platform-specific problem type: bug problem that needs to be addressed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants