From f911d7ecd99c4f0b67131b24b286a569c54c9655 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 2 Oct 2023 17:48:42 +0200 Subject: [PATCH] =?UTF-8?q?[3.12]=20gh-108963:=20using=20random=20to=20gen?= =?UTF-8?q?erate=20unique=20string=20in=20sys.intern=20test=20=E2=80=A6=20?= =?UTF-8?q?(#110216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gh-108963: using random to generate unique string in sys.intern test (#109491) (cherry picked from commit 44b1e4ea4842c6cdc1bedba7aaeb93f236b3ec08) Co-authored-by: AN Long --- Lib/test/test_sys.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index c3e9f9c4068..0b8529a9b6a 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -4,6 +4,7 @@ import gc import locale import operator import os +import random import struct import subprocess import sys @@ -19,10 +20,6 @@ import unittest import warnings -# 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): @@ -685,10 +682,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)