Skip to content
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

stubtest: Fix wrong assumption about relative path #12282

Merged
merged 1 commit into from Mar 4, 2022

Commits on Mar 3, 2022

  1. stubtest: Fix wrong assumption about relative path

    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 <slev@altlinux.org>
    stanislavlevin committed Mar 3, 2022
    Configuration menu
    Copy the full SHA
    073ea95 View commit details
    Browse the repository at this point in the history