diff options
author | Gregory P. Smith <greg@krypto.org> | 2015-12-14 04:09:42 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2015-12-14 04:09:42 (GMT) |
commit | 6edadfc9ca0934324e517fc9f9bdd902319825df (patch) | |
tree | de01df4779ae662327a0a60a8adf81cb1f730325 /Lib/test/test_cmd_line.py | |
parent | e847d7170d3f41b1ec773ab203c11f1addd6d4ac (diff) | |
parent | 8c084eb77d69ec1527fad943a4031b1b29193e98 (diff) | |
download | cpython-6edadfc9ca0934324e517fc9f9bdd902319825df.zip cpython-6edadfc9ca0934324e517fc9f9bdd902319825df.tar.gz cpython-6edadfc9ca0934324e517fc9f9bdd902319825df.tar.bz2 |
* Re-fix issue #19284: Don't generate the no-op -R command line
parameter to "enable" the always on sys.flags.hash_randomization
in _args_from_interpreter_flags() used by multiprocessing and
some unittests. This simplifies the code.
* assert_python_ok docstring typo fix.
* Fix test_cmd_line not to fail if PYTHONHASHSEED is set to a fixed seed.
Diffstat (limited to 'Lib/test/test_cmd_line.py')
-rw-r--r-- | Lib/test/test_cmd_line.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index 0feb63f..dce418b 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)' |