Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8a00abc

Browse files
committed
Make the regrtest.py -l (findleaks) option considerably less obnoxious.
First, only report garbage that the GC cannot free. Second, only report the number of objects found, not their repr(). People can dig deeper on their own if they find a leak.
1 parent 1ea8949 commit 8a00abc

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

Lib/test/regrtest.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
-x: exclude -- arguments are tests to *exclude*
1515
-s: single -- run only a single test (see below)
1616
-r: random -- randomize test execution order
17-
-l: findleaks -- if GC is available detect and print cyclic garbage
17+
-l: findleaks -- if GC is available detect tests that leak memory
1818
--have-resources -- run tests that require large resources (time/space)
1919
2020
If non-option arguments are present, they are names for tests to run,
@@ -92,10 +92,13 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
9292
try:
9393
import gc
9494
except ImportError:
95-
print 'cycle garbage collection not available'
95+
print 'No GC available, disabling findleaks.'
9696
findleaks = 0
9797
else:
98-
gc.set_debug(gc.DEBUG_SAVEALL)
98+
# Uncomment the line below to report garbage that is not
99+
# freeable by reference counting alone. By default only
100+
# garbage that is not collectable by the GC is reported.
101+
#gc.set_debug(gc.DEBUG_SAVEALL)
99102
found_garbage = []
100103

101104
if single:
@@ -141,7 +144,10 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
141144
if findleaks:
142145
gc.collect()
143146
if gc.garbage:
144-
print "garbage:", repr(gc.garbage)
147+
print "Warning: test created", len(gc.garbage),
148+
print "uncollectable object(s)."
149+
# move the uncollectable objects somewhere so we don't see
150+
# them again
145151
found_garbage.extend(gc.garbage)
146152
del gc.garbage[:]
147153
# Unload the newly imported modules (best effort finalization)

0 commit comments

Comments
 (0)