You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
stubtest: Fix wrong assumption about relative path (#12282)
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]>
0 commit comments