-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Tests from mypy/test/teststubtest.py fail without pytest-xdist or with v2.3.0 #11019
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
Labels
Comments
bmwiedemann
pushed a commit
to bmwiedemann/openSUSE
that referenced
this issue
Jan 23, 2022
https://build.opensuse.org/request/show/948161 by user sebix + dimstar_suse - Skip teststubtest because we use a pytest-xdist version which is not allowed by upstream -- gh#python/mypy#11019 (forwarded request 948145 from bnavigator)
stanislavlevin
added a commit
to stanislavlevin/mypy
that referenced
this issue
Mar 3, 2022
Description: `run_stubtest` creates temp directory and prepend `sys.path` with relative path (dot `.`) wrongly assuming that the dot will be resolved to absolute path on *every* import attempt. But in Python dot(`.`) in sys.path is actually resolved by PathFinder and cached in `sys.path_importer_cache` like: ``` sys.path_importer_cache['.'] FileFinder('/somepath/.') ``` later calls for `find_module` return None and import of `test_module` fails. This resulted in only the first test in stubtest's suite passed in non-pytest-xdist environments. This issue was hidden with bug or feature in pytest-xdist < 2.3.0: pytest-dev/pytest-xdist#421 It was fixed in pytest-xdist 2.3.0: pytest-dev/pytest-xdist#667 - sys.path for pytest-xdist < 2.3.0 `'.', 'project_path', ''` - sys.path for pytest-xdist >= 2.3.0 or without xdist `'.', 'project_path'` Fix: In Python for denoting cwd the empty path `''` can be used as a special case, but for readability `sys.path` is prepended with resolved absolute path of temp directory. Also it's essential to restore back `sys.path` after a test to not break subsequent tests. Fixes: python#11019 Signed-off-by: Stanislav Levin <[email protected]>
hauntsaninja
pushed a commit
that referenced
this issue
Mar 4, 2022
Fixes #11019 `run_stubtest` creates temp directory and prepend `sys.path` with relative path (dot `.`) wrongly assuming that the dot will be resolved to absolute path on *every* import attempt. But in Python dot(`.`) in sys.path is actually resolved by PathFinder and cached in `sys.path_importer_cache` like: ``` sys.path_importer_cache['.'] FileFinder('/somepath/.') ``` later calls for `find_module` return None and import of `test_module` fails. This resulted in only the first test in stubtest's suite passed in non-pytest-xdist environments. This issue was hidden with bug or feature in pytest-xdist < 2.3.0: pytest-dev/pytest-xdist#421 It was fixed in pytest-xdist 2.3.0: pytest-dev/pytest-xdist#667 - sys.path for pytest-xdist < 2.3.0 `'.', 'project_path', ''` - sys.path for pytest-xdist >= 2.3.0 or without xdist `'.', 'project_path'` In Python for denoting cwd the empty path `''` can be used as a special case, but for readability `sys.path` is prepended with resolved absolute path of temp directory. Also it's essential to restore back `sys.path` after a test to not break subsequent tests. Signed-off-by: Stanislav Levin <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Report
Hi,
I have noticed that tests from
mypy/test/teststubtest.py
fail with pytest-xdist 2.3.0. This is the faulty commit:pytest-dev/pytest-xdist@56e631b
It is especially problematic because they also fail without pytest-xdist, so I am not sure the bug is actually pytest-xdist's fault.
I understand that you have pinned an older version of pytest-xdist but some day you might still to have to deal with this issue.
To Reproduce
Here is an example Dockerfile which you can edit to test the faulty commit and its working parent. Getting rid of
pytest-xdist
does not fix the issue either.Expected Behavior
Tests should pass.
Actual Behavior
Tests fail because of a
sys.path
problem, e.g.:Your Environment
mypy.ini
(and other config files): N/AThe text was updated successfully, but these errors were encountered: