mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-11 21:13:52 -05:00
Deactivate virtualenv even if it has been activated manually
This commit is contained in:
@@ -37,8 +37,10 @@ fish )
|
||||
;;
|
||||
esac
|
||||
|
||||
prefix="${PYENV_ACTIVATE:-${VIRTUAL_ENV}}"
|
||||
|
||||
if [ -n "$VERBOSE" ]; then
|
||||
echo " echo \"pyenv-virtualenv: deactivate ${PYENV_ACTIVATE##*/}\" 1>&2;"
|
||||
echo " echo \"pyenv-virtualenv: deactivate ${prefix##*/}\" 1>&2;"
|
||||
fi
|
||||
|
||||
if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then
|
||||
@@ -50,7 +52,7 @@ fi
|
||||
case "$shell" in
|
||||
fish )
|
||||
cat <<EOS
|
||||
setenv PYENV_DEACTIVATE "$PYENV_ACTIVATE";
|
||||
setenv PYENV_DEACTIVATE "$prefix";
|
||||
set -e PYENV_ACTIVATE;
|
||||
deactivate;
|
||||
else;
|
||||
@@ -58,7 +60,7 @@ EOS
|
||||
;;
|
||||
* )
|
||||
cat <<EOS
|
||||
export PYENV_DEACTIVATE="$PYENV_ACTIVATE";
|
||||
export PYENV_DEACTIVATE="$prefix";
|
||||
unset PYENV_ACTIVATE;
|
||||
deactivate;
|
||||
else
|
||||
|
||||
@@ -102,6 +102,25 @@ fi;
|
||||
EOS
|
||||
}
|
||||
|
||||
@test "deactivate virtualenv which has been activated manually" {
|
||||
export PYENV_VIRTUALENV_INIT=1
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"
|
||||
|
||||
PYENV_SHELL="bash" run pyenv-sh-deactivate
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
if declare -f deactivate 1>/dev/null 2>&1; then
|
||||
export PYENV_DEACTIVATE="$VIRTUAL_ENV";
|
||||
unset PYENV_ACTIVATE;
|
||||
deactivate;
|
||||
else
|
||||
echo "pyenv-virtualenv: no virtualenv has been activated." 1>&2;
|
||||
false;
|
||||
fi;
|
||||
EOS
|
||||
}
|
||||
|
||||
@test "deactivate virtualenv (fish)" {
|
||||
export PYENV_VIRTUALENV_INIT=1
|
||||
export PYENV_ACTIVATE="${PYENV_ROOT}/versions/venv"
|
||||
@@ -177,6 +196,26 @@ else;
|
||||
end;
|
||||
EOS
|
||||
}
|
||||
|
||||
@test "deactivate virtualenv which has been activated manually (fish)" {
|
||||
export PYENV_VIRTUALENV_INIT=1
|
||||
export VIRTUAL_ENV="${PYENV_ROOT}/versions/venv"
|
||||
|
||||
PYENV_SHELL="fish" run pyenv-sh-deactivate
|
||||
|
||||
assert_success
|
||||
assert_output <<EOS
|
||||
if functions -q deactivate;
|
||||
setenv PYENV_DEACTIVATE "$VIRTUAL_ENV";
|
||||
set -e PYENV_ACTIVATE;
|
||||
deactivate;
|
||||
else;
|
||||
echo "pyenv-virtualenv: no virtualenv has been activated." 1>&2;
|
||||
false;
|
||||
end;
|
||||
EOS
|
||||
}
|
||||
|
||||
@test "should fail if deactivate is invoked as a command" {
|
||||
run pyenv-deactivate
|
||||
|
||||
|
||||
Reference in New Issue
Block a user