Skip to content

Commit 44b1e4e

Browse files
authored
gh-108963: using random to generate unique string in sys.intern test (#109491)
1 parent f16e81f commit 44b1e4e

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

Lib/test/test_sys.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import locale
66
import operator
77
import os
8+
import random
89
import struct
910
import subprocess
1011
import sys
@@ -30,10 +31,6 @@ def requires_subinterpreters(meth):
3031
'subinterpreters required')(meth)
3132

3233

33-
# count the number of test runs, used to create unique
34-
# strings to intern in test_intern()
35-
INTERN_NUMRUNS = 0
36-
3734
DICT_KEY_STRUCT_FORMAT = 'n2BI2n'
3835

3936
class DisplayHookTest(unittest.TestCase):
@@ -696,10 +693,8 @@ def test_43581(self):
696693
self.assertEqual(sys.__stdout__.encoding, sys.__stderr__.encoding)
697694

698695
def test_intern(self):
699-
global INTERN_NUMRUNS
700-
INTERN_NUMRUNS += 1
701696
self.assertRaises(TypeError, sys.intern)
702-
s = "never interned before" + str(INTERN_NUMRUNS)
697+
s = "never interned before" + str(random.randrange(0, 10**9))
703698
self.assertTrue(sys.intern(s) is s)
704699
s2 = s.swapcase().swapcase()
705700
self.assertTrue(sys.intern(s2) is s)
@@ -717,9 +712,7 @@ def __hash__(self):
717712

718713
@requires_subinterpreters
719714
def test_subinterp_intern_dynamically_allocated(self):
720-
global INTERN_NUMRUNS
721-
INTERN_NUMRUNS += 1
722-
s = "never interned before" + str(INTERN_NUMRUNS)
715+
s = "never interned before" + str(random.randrange(0, 10**9))
723716
t = sys.intern(s)
724717
self.assertIs(t, s)
725718

0 commit comments

Comments
 (0)