diff options
author | AN Long <aisk@users.noreply.github.com> | 2023-10-02 11:07:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-02 11:07:56 (GMT) |
commit | 44b1e4ea4842c6cdc1bedba7aaeb93f236b3ec08 (patch) | |
tree | d730d24fb0d6ba98f8609347f8ef7bf834d5261a | |
parent | f16e81f368d08891e28dc1f038c1826ea80d7801 (diff) | |
download | cpython-44b1e4ea4842c6cdc1bedba7aaeb93f236b3ec08.zip cpython-44b1e4ea4842c6cdc1bedba7aaeb93f236b3ec08.tar.gz cpython-44b1e4ea4842c6cdc1bedba7aaeb93f236b3ec08.tar.bz2 |
gh-108963: using random to generate unique string in sys.intern test (#109491)
-rw-r--r-- | Lib/test/test_sys.py | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 1605017..ae241d7 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -5,6 +5,7 @@ import gc import locale import operator import os +import random import struct import subprocess import sys @@ -30,10 +31,6 @@ def requires_subinterpreters(meth): 'subinterpreters required')(meth) -# count the number of test runs, used to create unique -# strings to intern in test_intern() -INTERN_NUMRUNS = 0 - DICT_KEY_STRUCT_FORMAT = 'n2BI2n' class DisplayHookTest(unittest.TestCase): @@ -696,10 +693,8 @@ class SysModuleTest(unittest.TestCase): self.assertEqual(sys.__stdout__.encoding, sys.__stderr__.encoding) def test_intern(self): - global INTERN_NUMRUNS - INTERN_NUMRUNS += 1 self.assertRaises(TypeError, sys.intern) - s = "never interned before" + str(INTERN_NUMRUNS) + s = "never interned before" + str(random.randrange(0, 10**9)) self.assertTrue(sys.intern(s) is s) s2 = s.swapcase().swapcase() self.assertTrue(sys.intern(s2) is s) @@ -717,9 +712,7 @@ class SysModuleTest(unittest.TestCase): @requires_subinterpreters def test_subinterp_intern_dynamically_allocated(self): - global INTERN_NUMRUNS - INTERN_NUMRUNS += 1 - s = "never interned before" + str(INTERN_NUMRUNS) + s = "never interned before" + str(random.randrange(0, 10**9)) t = sys.intern(s) self.assertIs(t, s) |