mirror of
https://github.com/python/cpython.git
synced 2024-12-13 03:45:42 +08:00
GH-104584: Fix test_capi.test_counter_optimizer() when run twice (#106171)
test_counter_optimizer() and test_long_loop() of test_capi now create a new function at each call. Otherwise, the optimizer counters are not the expected values when the test is run more than once.
This commit is contained in:
parent
2ac3eec103
commit
adaacf26d3
@ -2372,10 +2372,14 @@ class TestOptimizerAPI(unittest.TestCase):
|
||||
self.assertEqual(_testinternalcapi.get_optimizer(), None)
|
||||
|
||||
def test_counter_optimizer(self):
|
||||
|
||||
def loop():
|
||||
for _ in range(1000):
|
||||
pass
|
||||
# Generate a new function at each call
|
||||
ns = {}
|
||||
exec(textwrap.dedent("""
|
||||
def loop():
|
||||
for _ in range(1000):
|
||||
pass
|
||||
"""), ns, ns)
|
||||
loop = ns['loop']
|
||||
|
||||
for repeat in range(5):
|
||||
opt = _testinternalcapi.get_counter_optimizer()
|
||||
@ -2388,18 +2392,23 @@ class TestOptimizerAPI(unittest.TestCase):
|
||||
def test_long_loop(self):
|
||||
"Check that we aren't confused by EXTENDED_ARG"
|
||||
|
||||
def nop():
|
||||
pass
|
||||
# Generate a new function at each call
|
||||
ns = {}
|
||||
exec(textwrap.dedent("""
|
||||
def nop():
|
||||
pass
|
||||
|
||||
def long_loop():
|
||||
for _ in range(10):
|
||||
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
|
||||
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
|
||||
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
|
||||
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
|
||||
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
|
||||
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
|
||||
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
|
||||
def long_loop():
|
||||
for _ in range(10):
|
||||
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
|
||||
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
|
||||
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
|
||||
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
|
||||
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
|
||||
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
|
||||
nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
|
||||
"""), ns, ns)
|
||||
long_loop = ns['long_loop']
|
||||
|
||||
opt = _testinternalcapi.get_counter_optimizer()
|
||||
with self.temporary_optimizer(opt):
|
||||
|
Loading…
Reference in New Issue
Block a user