-
Notifications
You must be signed in to change notification settings - Fork 233
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
xdist adds current directory to sys.path #421
Comments
In fact, the diagnosis on my end is almost exactly the same as #376 - the second entry changes from the python executable dir to the empty string. So I guess a regression rather than a new bug? |
Hi @ndevenish, Are you on Python 2.7? I ask because you might have the same issue as #414. |
Yes, Initially, but the error (path turning into FROM python:3
RUN pip3 install -U pytest-xdist==1.26.1
RUN printf "import sys\ndef test_path():\n assert not '' in sys.path\n" >> test_path.py
RUN pytest test_path.py
RUN pytest test_path.py -n 1 So, no
It looks to be the same root cause though. |
the problem is the way execnet runs python, vs setuptools console_scripts entry_points when you run with
however execnet runs with
and so the path is:
|
fix sys.path for local workers Fixes #421
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [pytest-xdist](https://github.com/pytest-dev/pytest-xdist) | `==2.2.1` -> `==2.3.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>pytest-dev/pytest-xdist</summary> ### [`v2.3.0`](https://github.com/pytest-dev/pytest-xdist/blob/master/CHANGELOG.rst#pytest-xdist-230-2021-06-16) [Compare Source](https://github.com/pytest-dev/pytest-xdist/compare/v2.2.1...v2.3.0) \=============================== ## Deprecations and Removals - `#​654 <https://github.com/pytest-dev/pytest-xdist/issues/654>`\_: Python 3.5 is no longer supported. ## Features - `#​646 <https://github.com/pytest-dev/pytest-xdist/issues/646>`\_: Add `--numprocesses=logical` flag, which automatically uses the number of logical CPUs available, instead of physical CPUs with `auto`. This is very useful for test suites which are not CPU-bound. - `#​650 <https://github.com/pytest-dev/pytest-xdist/issues/650>`\_: Added new `pytest_handlecrashitem` hook to allow handling and rescheduling crashed items. ## Bug Fixes - `#​421 <https://github.com/pytest-dev/pytest-xdist/issues/421>`\_: Copy the parent process sys.path into local workers, to work around execnet's python -c adding the current directory to sys.path. - `#​638 <https://github.com/pytest-dev/pytest-xdist/issues/638>`\_: Fix issue caused by changing the branch name of the pytest repository. ## Trivial Changes - `#​592 <https://github.com/pytest-dev/pytest-xdist/issues/592>`\_: Replace master with controller where ever possible. - `#​643 <https://github.com/pytest-dev/pytest-xdist/issues/643>`\_: Use 'main' to refer to pytest default branch in tox env names. </details> --- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Renovate will not automatically rebase this PR, because other commits have been found. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/GoogleCloudPlatform/python-docs-samples).
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]>
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]>
With 1.26.1.
Obviously this can cause problems/change behaviour depending on where you are running the tests from.
Possibly related to #376?
The text was updated successfully, but these errors were encountered: