-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
pytest cache files contain absolute paths #3968
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
Comments
i clearly see the appeal of this desire - but i'd like to get a clear understandign of what it means with regard to sys.path and locations of files we should match the cpython behaviour more closely there and allow people to sensibly rename things but we definitively also need to be very careful about import mismatches relating to different locations of files which are accidentally different but share a common importation prefix |
Yes, it makes sense to be careful about sourcing, sys.path and site-packages are wildly variable dependent on the platform used. I think for the purposes of .pyc files, this shouldn't be too onerous to resolve, from what I understand .pyc files will either end up in an adjacent |
@scw i am currently under the impression the problem is mainly when pytest alters sys.path to be able to import other modules - we need to be able to keep apart "copies" or test files with the same name but different locations |
OK, how about this -- when parsing the |
@scw the problem i fear is files with tests from 2 different locations ending up with the same import name and relative filename additionally some of that might be tied with py.path.local limitations (i havent digged in deep yet) |
OK, can you help me understand what needs to be researched in order to fix this? Here's my understanding of how to handle this if there are multiple duplicates on
Say there are two copies of |
The .pyc files that pytest creates with the
PYTEST
suffix include hardcoded full paths in their embedded source representation. This means that if the file moves, it will no longer be valid if the original location is removed, and pytest will throw errors trying to import these cached files. I checked what the CPython .pyc files are doing differently (which work after moving), and it looks like this is due to how pytest writes the cache files. Here's a quick test usinguncompyle6
, showing the headers only (decompiled file contents are exactly the same) using a file fromscipy
:You can see from the "Embedded file name" line that a CPython .pyc contains a relative path, but the PYTEST version contains an absolute path. Systems such as conda typically distribute compiled components, and it would be nice to be able to distribute PYTEST files this way, and more generally be able to move environments.
Here's an oversimplified fix:
and use this value for
fn.strpath
inpytest/src/_pytest/assertion/rewrite.py
Line 414 in e0539e6
I can make a PR, but it wasn't clear from my reading if the full path is explicitly required somehow by pytest, and figured I'd ask as an issue first.
Environment:
x64 Windows 10, pytest 3.7.4, Python 3.6.6, conda
The text was updated successfully, but these errors were encountered: