pytest-dev / pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
https://pytest.org
MIT License
11.89k stars 2.65k forks source link

Windows symlink broken by Path().resolve() #5905

Closed adamkerz closed 4 years ago

adamkerz commented 4 years ago

On Windows 10 (v1903, 18362.356) I have created a D: drive using Subst. My tests used to work, but I recently upgraded pytest and found that I now get this error message for every test file:

____________________________________________ ERROR collecting test_feature_toggles.py _____________________________________________
import file mismatch:
imported module 'tests.unit.test_feature_toggles' has this __file__ attribute:
  D:\development\psma\api\api-master\api_services\pav\imp\src\tests\unit\test_feature_toggles.py
which is not the same as the test file we want to collect:
  C:\d_drive\development\psma\api\api-master\api_services\pav\imp\src\tests\unit\test_feature_toggles.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

Well, they are the same file, deleting ALL pycache/.pyc files has no impact and I believe the problem was introduced in this PR: https://github.com/pytest-dev/pytest/pull/5564

I believe this may be the same cause of a different bug: https://github.com/pytest-dev/pytest/issues/5826

Is it possible to use Path().absolute() instead?

Pytest version: 5.1.3

(.venv) D:\development\psma\api\api-master\api_services\pav\imp\src>pip list
Package             Version   Location
------------------- --------- ---------------------------------------------------------
aniso8601           8.0.0
apispec             0.39.0
argcomplete         1.9.3
atomicwrites        1.3.0
attrdict            2.0.1
attrs               19.1.0
Beaker              1.11.0
blinker             1.4
boto3               1.9.58
botocore            1.12.233
certifi             2019.9.11
cfn-flip            1.2.1
chardet             3.0.4
Click               7.0
colorama            0.4.1
common-utils        0.1       d:\development\psma\api\api-master\libraries\common_utils
config-load         0.1       d:\development\psma\api\api-master\libraries\config_load
coverage            4.5.4
docutils            0.15.2
durationpy          0.5
elasticsearch       2.4.0
factory-boy         2.12.0
Faker               2.0.2
flasgger            0.9.2
Flask               1.0.2
Flask-Cors          3.0.7
Flask-RESTful       0.3.6
Flask-SQLAlchemy    2.3.2
future              0.16.0
fuzzywuzzy          0.17.0
hjson               3.0.1
idna                2.8
importlib-metadata  0.23
itsdangerous        1.1.0
Jinja2              2.10.1
jmespath            0.9.4
json-logging        1.0.3
jsonschema          3.0.2
kappa               0.6.0
lambda-packages     0.20.0
MarkupSafe          1.1.1
marshmallow         2.16.3
mistune             0.8.4
mock                3.0.5
more-itertools      7.2.0
multi-key-dict      2.0.3
packaging           19.2
pav-data            0.0.1     d:\development\psma\api\api-master\data_services\pav_data
phonetics           1.0.5
pip                 19.2.3
placebo             0.9.0
pluggy              0.13.0
psycopg2-binary     2.7.6.1
py                  1.8.0
pynamodb            3.3.1
pyparsing           2.4.2
pyrsistent          0.15.4
pytest              5.1.3
pytest-cov          2.7.1
pytest-mock         1.10.4
python-crfsuite     0.9.6
python-dateutil     2.8.0
python-slugify      1.2.4
pytz                2019.2
PyYAML              5.1.2
requests            2.22.0
s3transfer          0.1.13
sentry-sdk          0.6.5
setuptools          28.8.0
six                 1.12.0
SQLAlchemy          1.2.14
text-unidecode      1.3
toml                0.10.0
tqdm                4.19.1
troposphere         2.5.1
Unidecode           1.1.1
urllib3             1.24.1
wcwidth             0.1.7
Werkzeug            0.16.0
wheel               0.33.6
wsgi-request-logger 0.4.6
zappa               0.48.2
zipp                0.6.0

To recreate, use subst to map a folder where you have tests into a new drive letter, cd to that folder on the new drive letter and try to run the tests again.

adamkerz commented 4 years ago

Confirmed: pytest==5.0.1 is fine pytest==5.1.0 exhibits the bug. This is a regression.

blueyed commented 4 years ago

Can you git-bisect it?

adamkerz commented 4 years ago

Yes, I will try to get time to do that, blueyed.

fabioz commented 4 years ago

This should be closed as a duplicate of https://github.com/pytest-dev/pytest/issues/5965 (since that one has a pull request).