]> granicus.if.org Git - python/commitdiff
threading_cleanup() failure marks test as ENV_CHANGED (#2500)
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 30 Jun 2017 08:59:52 +0000 (10:59 +0200)
committerGitHub <noreply@github.com>
Fri, 30 Jun 2017 08:59:52 +0000 (10:59 +0200)
If threading_cleanup() fails to cleanup threads, set a a new
support.environment_altered flag to true, flag uses by save_env which
is used by regrtest to check if a test altered the environment. At
the end, the test file fails with ENV_CHANGED instead of SUCCESS, to
report that it altered the environment.

Lib/test/libregrtest/runtest.py
Lib/test/libregrtest/save_env.py
Lib/test/support/__init__.py

index fda4ca1ebca094fda48280963d7324b5db35b058..0210409817bb68f8128a84cd6992b4ad80c339f5 100644 (file)
@@ -103,6 +103,9 @@ def runtest(ns, test):
         faulthandler.dump_traceback_later(ns.timeout, exit=True)
     try:
         support.match_tests = ns.match_tests
+        # reset the environment_altered flag to detect if a test altered
+        # the environment
+        support.environment_altered = False
         if ns.failfast:
             support.failfast = True
         if output_on_failure:
index 8309f266bfbe9be715d86d678cecee6512e1aed7..3c45621390be44f7b6b2bdb29382a1caa770782a 100644 (file)
@@ -268,7 +268,13 @@ class saved_test_environment:
     def __exit__(self, exc_type, exc_val, exc_tb):
         saved_values = self.saved_values
         del self.saved_values
-        support.gc_collect()  # Some resources use weak references
+
+        # Some resources use weak references
+        support.gc_collect()
+
+        # Read support.environment_altered, set by support helper functions
+        self.changed |= support.environment_altered
+
         for name, get, restore in self.resource_info():
             current = get()
             original = saved_values.pop(name)
index 817ba675e2a2a548a6a0a53c3b1b6c5514f558af..3cfa487ba96a4ce6ce1eb7b78e98f0f078c20591 100644 (file)
@@ -2011,6 +2011,14 @@ def modules_cleanup(oldmodules):
 #=======================================================================
 # Threading support to prevent reporting refleaks when running regrtest.py -R
 
+# Flag used by saved_test_environment of test.libregrtest.save_env,
+# to check if a test modified the environment. The flag should be set to False
+# before running a new test.
+#
+# For example, threading_cleanup() sets the flag is the function fails
+# to cleanup threads.
+environment_altered = False
+
 # NOTE: we use thread._count() rather than threading.enumerate() (or the
 # moral equivalent thereof) because a threading.Thread object is still alive
 # until its __bootstrap() method has returned, even after it has been
@@ -2026,6 +2034,8 @@ def threading_setup():
         return 1, ()
 
 def threading_cleanup(*original_values):
+    global environment_altered
+
     if not _thread:
         return
     _MAX_COUNT = 100
@@ -2037,6 +2047,8 @@ def threading_cleanup(*original_values):
         time.sleep(0.01)
         gc_collect()
     else:
+        environment_altered = True
+
         dt = time.monotonic() - t0
         print("Warning -- threading_cleanup() failed to cleanup %s threads "
               "after %.0f sec (count: %s, dangling: %s)"