mirror of
https://github.com/python/cpython.git
synced 2025-08-12 04:49:01 +00:00
bpo-37885: venv: Don't produce unbound variable warning on deactivate (GH-15973)
Before, running deactivate from a bash shell configured to treat undefined variables as errors (`set -u`) would produce a warning:
```
$ python3 -m venv test
$ source test/bin/activate
(test) $ deactivate
-bash: $1: unbound variable
```
(cherry picked from commit 5209e586b7
)
Co-authored-by: Daniel Abrahamsson <hamsson@gmail.com>
This commit is contained in:
parent
893653357c
commit
63eefc3567
3 changed files with 22 additions and 1 deletions
|
@ -9,6 +9,7 @@ import ensurepip
|
|||
import os
|
||||
import os.path
|
||||
import re
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
|
@ -338,6 +339,25 @@ class BasicTest(BaseTest):
|
|||
'pool.terminate()'])
|
||||
self.assertEqual(out.strip(), "python".encode())
|
||||
|
||||
@unittest.skipIf(os.name == 'nt', 'not relevant on Windows')
|
||||
def test_deactivate_with_strict_bash_opts(self):
|
||||
bash = shutil.which("bash")
|
||||
if bash is None:
|
||||
self.skipTest("bash required for this test")
|
||||
rmtree(self.env_dir)
|
||||
builder = venv.EnvBuilder(clear=True)
|
||||
builder.create(self.env_dir)
|
||||
activate = os.path.join(self.env_dir, self.bindir, "activate")
|
||||
test_script = os.path.join(self.env_dir, "test_strict.sh")
|
||||
with open(test_script, "w") as f:
|
||||
f.write("set -euo pipefail\n"
|
||||
f"source {activate}\n"
|
||||
"deactivate\n")
|
||||
out, err = check_output([bash, test_script])
|
||||
self.assertEqual(out, "".encode())
|
||||
self.assertEqual(err, "".encode())
|
||||
|
||||
|
||||
@requireVenvCreate
|
||||
class EnsurePipTest(BaseTest):
|
||||
"""Test venv module installation of pip."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue