@@ -209,17 +209,25 @@ def once(x): # line 301
209
209
@pytest .mark .skipif (not testenv .C_TRACER , reason = "Only the C tracer has refcounting issues" )
210
210
# In fact, sysmon explicitly holds onto all code objects,
211
211
# so this will definitely fail with sysmon.
212
- def test_eval_codeobject_leak (self ) -> None :
212
+ @pytest .mark .parametrize ("branch" , [False , True ])
213
+ def test_eval_codeobject_leak (self , branch : bool ) -> None :
213
214
# https://github.com/nedbat/coveragepy/issues/1924
214
215
code = """\
215
- for i in range(100_000 ):
216
+ for i in range(10_000 ):
216
217
r = eval("'a' + '1'")
217
218
assert r == 'a1'
218
219
"""
219
- ram_0 = osinfo .process_ram ()
220
- self .check_coverage (code , [1 , 2 , 3 ], "" )
221
- ram_growth = osinfo .process_ram () - ram_0
222
- assert ram_growth < 2_000 * 1024
220
+ # Looking for leaks is hard. We consider the leak fixed if at least
221
+ # one of our loops only increased the footprint by a small amount.
222
+ base = osinfo .process_ram ()
223
+ deltas = []
224
+ for _ in range (10 ):
225
+ self .check_coverage (code , [1 , 2 , 3 ], "" , branch = branch )
226
+ now = osinfo .process_ram ()
227
+ deltas .append (now - base )
228
+ print (f"Mem delta: { (now - base )// 1024 } " )
229
+ base = now
230
+ assert any (d < 50 * 1024 for d in deltas )
223
231
224
232
225
233
class MemoryFumblingTest (CoverageTest ):
0 commit comments