Skip to content

ImportPathMismatchError on WindowsPath #8076

Closed
@jaraco

Description

@jaraco

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed as duplicateissue is a duplicate of another issueplatform: windowswindows platform-specific problemtype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions