File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed
Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,9 @@ def runtest(ns, test):
103103 faulthandler .dump_traceback_later (ns .timeout , exit = True )
104104 try :
105105 support .match_tests = ns .match_tests
106+ # reset the environment_altered flag to detect if a test altered
107+ # the environment
108+ support .environment_altered = False
106109 if ns .failfast :
107110 support .failfast = True
108111 if output_on_failure :
Original file line number Diff line number Diff line change @@ -268,7 +268,13 @@ def __enter__(self):
268268 def __exit__ (self , exc_type , exc_val , exc_tb ):
269269 saved_values = self .saved_values
270270 del self .saved_values
271- support .gc_collect () # Some resources use weak references
271+
272+ # Some resources use weak references
273+ support .gc_collect ()
274+
275+ # Read support.environment_altered, set by support helper functions
276+ self .changed |= support .environment_altered
277+
272278 for name , get , restore in self .resource_info ():
273279 current = get ()
274280 original = saved_values .pop (name )
Original file line number Diff line number Diff line change @@ -2011,6 +2011,14 @@ def modules_cleanup(oldmodules):
20112011#=======================================================================
20122012# Threading support to prevent reporting refleaks when running regrtest.py -R
20132013
2014+ # Flag used by saved_test_environment of test.libregrtest.save_env,
2015+ # to check if a test modified the environment. The flag should be set to False
2016+ # before running a new test.
2017+ #
2018+ # For example, threading_cleanup() sets the flag is the function fails
2019+ # to cleanup threads.
2020+ environment_altered = False
2021+
20142022# NOTE: we use thread._count() rather than threading.enumerate() (or the
20152023# moral equivalent thereof) because a threading.Thread object is still alive
20162024# until its __bootstrap() method has returned, even after it has been
@@ -2026,6 +2034,8 @@ def threading_setup():
20262034 return 1 , ()
20272035
20282036def threading_cleanup (* original_values ):
2037+ global environment_altered
2038+
20292039 if not _thread :
20302040 return
20312041 _MAX_COUNT = 100
@@ -2037,6 +2047,8 @@ def threading_cleanup(*original_values):
20372047 time .sleep (0.01 )
20382048 gc_collect ()
20392049 else :
2050+ environment_altered = True
2051+
20402052 dt = time .monotonic () - t0
20412053 print ("Warning -- threading_cleanup() failed to cleanup %s threads "
20422054 "after %.0f sec (count: %s, dangling: %s)"
You can’t perform that action at this time.
0 commit comments