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

fix flaky failure in export_integration_test.py #21756

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

tdyas
Copy link
Contributor

@tdyas tdyas commented Dec 13, 2024

src/python/pants/backend/python/goals/export_integration_test.py was failing for me consistently in a PR of mine and on main locally. Not sure why it passes elsewhere.

See this failure for example: https://github.com/pantsbuild/pants/actions/runs/12306576175/job/34349676205?pr=21745#step:10:478

The test is checking whether a venv activation script has a certain prompt with both a resolve name and the Python version. The test also checks whether the quote character starting that string begins with a double-quote character.

On my system for main and in the PR on CI, that quote character became a single quote instead so the test fails.

Use a regex and allow either quote character.

@tdyas tdyas added category:bugfix Bug fixes for released features release-notes:not-required PR doesn't require mention in release notes category:internal CI, fixes for not-yet-released features, etc. and removed category:bugfix Bug fixes for released features labels Dec 13, 2024
@tdyas
Copy link
Contributor Author

tdyas commented Dec 13, 2024

Below is the text of the bin/activate script as seen in the test on my system.

Note the relevant part is PS1='(a/3.11.11) '"${PS1:-}".

Yet, the existing test looks for f'PS1="({resolve}/{platform.python_version()}) ' which looks for a double quote and not a single quote.

# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly

deactivate () {
    # reset old environment variables
    if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
        PATH="${_OLD_VIRTUAL_PATH:-}"
        export PATH
        unset _OLD_VIRTUAL_PATH
    fi
    if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
        PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
        export PYTHONHOME
        unset _OLD_VIRTUAL_PYTHONHOME
    fi

    # Call hash to forget past commands. Without forgetting
    # past commands the $PATH changes we made may not be respected
    hash -r 2> /dev/null

    if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
        PS1="${_OLD_VIRTUAL_PS1:-}"
        export PS1
        unset _OLD_VIRTUAL_PS1
    fi

    unset VIRTUAL_ENV
    unset VIRTUAL_ENV_PROMPT
    if [ ! "${1:-}" = "nondestructive" ] ; then
    # Self destruct!
        unset -f deactivate
    fi
}

# unset irrelevant variables
deactivate nondestructive

VIRTUAL_ENV=dist/export/python/virtualenvs/a/3.11.11
export VIRTUAL_ENV

_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/"bin":$PATH"
export PATH

# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "${PYTHONHOME:-}" ] ; then
    _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
    unset PYTHONHOME
fi

if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
    _OLD_VIRTUAL_PS1="${PS1:-}"
    PS1='(a/3.11.11) '"${PS1:-}"
    export PS1
    VIRTUAL_ENV_PROMPT='(a/3.11.11) '
    export VIRTUAL_ENV_PROMPT
fi

# Call hash to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
hash -r 2> /dev/null

@tdyas tdyas merged commit 5c4e66e into pantsbuild:main Dec 13, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:internal CI, fixes for not-yet-released features, etc. release-notes:not-required PR doesn't require mention in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants