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.
1 file changed