@@ -184,7 +184,7 @@ def usage(msg):
184184def main (tests = None , testdir = None , verbose = 0 , quiet = False , generate = False ,
185185 exclude = False , single = False , randomize = False , fromfile = None ,
186186 findleaks = False , use_resources = None , trace = False , coverdir = 'coverage' ,
187- runleaks = False , huntrleaks = False , verbose2 = False , debug = False ,
187+ runleaks = False , huntrleaks = None , verbose2 = False , debug = False ,
188188 start = None ):
189189 """Execute a test suite.
190190
@@ -518,7 +518,7 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS):
518518 return stdtests + tests
519519
520520def runtest (test , generate , verbose , quiet , testdir = None ,
521- huntrleaks = False , debug = False ):
521+ huntrleaks = None , debug = False ):
522522 """Run a single test.
523523
524524 test -- the name of the test
@@ -545,7 +545,7 @@ def runtest(test, generate, verbose, quiet, testdir=None,
545545 cleanup_test_droppings (test , verbose )
546546
547547def runtest_inner (test , generate , verbose , quiet ,
548- testdir = None , huntrleaks = False , debug = False ):
548+ testdir = None , huntrleaks = None , debug = False ):
549549 test_support .unload (test )
550550 if not testdir :
551551 testdir = findtestdir ()
@@ -670,7 +670,7 @@ def cleanup_test_droppings(testname, verbose):
670670
671671def dash_R (the_module , test , indirect_test , huntrleaks ):
672672 # This code is hackish and inelegant, but it seems to do the job.
673- import copy_reg
673+ import copy_reg , _abcoll
674674
675675 if not hasattr (sys , 'gettotalrefcount' ):
676676 raise Exception ("Tracking reference leaks requires a debug build "
@@ -680,6 +680,9 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
680680 fs = warnings .filters [:]
681681 ps = copy_reg .dispatch_table .copy ()
682682 pic = sys .path_importer_cache .copy ()
683+ abcs = {obj : obj ._ABCMeta__registry .copy ()
684+ for abc in [getattr (_abcoll , a ) for a in _abcoll .__all__ ]
685+ for obj in abc .__subclasses__ () + [abc ]}
683686
684687 if indirect_test :
685688 def run_the_test ():
@@ -694,13 +697,13 @@ def run_the_test():
694697 repcount = nwarmup + ntracked
695698 print ("beginning" , repcount , "repetitions" , file = sys .stderr )
696699 print (("1234567890" * (repcount // 10 + 1 ))[:repcount ], file = sys .stderr )
697- dash_R_cleanup (fs , ps , pic )
700+ dash_R_cleanup (fs , ps , pic , abcs )
698701 for i in range (repcount ):
699702 rc = sys .gettotalrefcount ()
700703 run_the_test ()
701704 sys .stderr .write ('.' )
702705 sys .stderr .flush ()
703- dash_R_cleanup (fs , ps , pic )
706+ dash_R_cleanup (fs , ps , pic , abcs )
704707 if i >= nwarmup :
705708 deltas .append (sys .gettotalrefcount () - rc - 2 )
706709 print (file = sys .stderr )
@@ -711,7 +714,7 @@ def run_the_test():
711714 print (msg , file = refrep )
712715 refrep .close ()
713716
714- def dash_R_cleanup (fs , ps , pic ):
717+ def dash_R_cleanup (fs , ps , pic , abcs ):
715718 import gc , copy_reg
716719 import _strptime , linecache , dircache
717720 import urlparse , urllib , urllib2 , mimetypes , doctest
@@ -725,10 +728,10 @@ def dash_R_cleanup(fs, ps, pic):
725728 sys .path_importer_cache .clear ()
726729 sys .path_importer_cache .update (pic )
727730
728- # Clear ABC registries.
731+ # Clear ABC registries, restoring previously saved ABC registries .
729732 for abc in [getattr (_abcoll , a ) for a in _abcoll .__all__ ]:
730733 for obj in abc .__subclasses__ () + [abc ]:
731- obj ._ABCMeta__registry . clear ()
734+ obj ._ABCMeta__registry = abcs . get ( obj , {}). copy ()
732735 obj ._ABCMeta__cache .clear ()
733736 obj ._ABCMeta__negative_cache .clear ()
734737
0 commit comments