summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/support/script_helper.py2
-rw-r--r--Lib/test/test_cmd_line.py18
2 files changed, 16 insertions, 4 deletions
diff --git a/Lib/test/support/script_helper.py b/Lib/test/support/script_helper.py
index 584b0e8eef..9c2e9ebdfb 100644
--- a/Lib/test/support/script_helper.py
+++ b/Lib/test/support/script_helper.py
@@ -127,7 +127,7 @@ def assert_python_ok(*args, **env_vars):
variables `env_vars` succeeds (rc == 0) and return a (return code, stdout,
stderr) tuple.
- If the __cleanenv keyword is set, env_vars is used a fresh environment.
+ If the __cleanenv keyword is set, env_vars is used as a fresh environment.
Python is started in isolated mode (command line option -I),
except if the __isolated keyword is set to False.
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 0feb63fd4e..dce418b65c 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -403,12 +403,24 @@ class CmdLineTest(unittest.TestCase):
# Verify that -R enables hash randomization:
self.verify_valid_flag('-R')
hashes = []
- for i in range(2):
+ if os.environ.get('PYTHONHASHSEED', 'random') != 'random':
+ env = dict(os.environ) # copy
+ # We need to test that it is enabled by default without
+ # the environment variable enabling it for us.
+ del env['PYTHONHASHSEED']
+ env['__cleanenv'] = '1' # consumed by assert_python_ok()
+ else:
+ env = {}
+ for i in range(3):
code = 'print(hash("spam"))'
- rc, out, err = assert_python_ok('-c', code)
+ rc, out, err = assert_python_ok('-c', code, **env)
self.assertEqual(rc, 0)
hashes.append(out)
- self.assertNotEqual(hashes[0], hashes[1])
+ hashes = sorted(set(hashes)) # uniq
+ # Rare chance of failure due to 3 random seeds honestly being equal.
+ self.assertGreater(len(hashes), 1,
+ msg='3 runs produced an identical random hash '
+ ' for "spam": {}'.format(hashes))
# Verify that sys.flags contains hash_randomization
code = 'import sys; print("random is", sys.flags.hash_randomization)'