Skip to content

Commit 09c1c69

Browse files
authored
Fix bad return code in bash activation if hashing is disabled (#2717)
1 parent 0a3816e commit 09c1c69

4 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎docs/changelog/2717.bugfix.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bad return code from activate.sh if hashing is disabled - by :user:'fenkes-ibm'.

‎src/virtualenv/activation/bash/activate.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ pydoc () {
8484
# The hash command must be called to get it to forget past
8585
# commands. Without forgetting past commands the $PATH changes
8686
# we made may not be respected
87-
hash -r 2>/dev/null
87+
hash -r 2>/dev/null || true

‎tests/unit/activation/conftest.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def __call__(self, monkeypatch, tmp_path):
7979
process = Popen(invoke, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
8080
raw_, _ = process.communicate()
8181
raw = raw_.decode()
82+
assert process.returncode == 0, raw
8283
except subprocess.CalledProcessError as exception:
8384
output = exception.output + exception.stderr
8485
assert not exception.returncode, output # noqa: PT017

‎tests/unit/activation/test_bash.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88

99
@pytest.mark.skipif(IS_WIN, reason="Github Actions ships with WSL bash")
10-
def test_bash(raise_on_non_source_class, activation_tester):
10+
@pytest.mark.parametrize("hashing_enabled", [True, False])
11+
def test_bash(raise_on_non_source_class, hashing_enabled, activation_tester):
1112
class Bash(raise_on_non_source_class):
1213
def __init__(self, session) -> None:
1314
super().__init__(
@@ -18,6 +19,11 @@ def __init__(self, session) -> None:
1819
"sh",
1920
"You must source this script: $ source ",
2021
)
22+
self.deactivate += " || exit 1"
23+
self._invoke_script.append("-h" if hashing_enabled else "+h")
24+
25+
def activate_call(self, script):
26+
return super().activate_call(script) + " || exit 1"
2127

2228
def print_prompt(self):
2329
return self.print_os_env_var("PS1")

0 commit comments

Comments
 (0)