]> granicus.if.org Git - python/commitdiff
Issue #7058: Added save/restore for argv and os.environ to runtest_inner
authorR. David Murray <rdmurray@bitdance.com>
Mon, 5 Oct 2009 17:03:09 +0000 (17:03 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Mon, 5 Oct 2009 17:03:09 +0000 (17:03 +0000)
in regrtest, with warnings if the called test modifies them.

Lib/test/regrtest.py
Misc/NEWS

index 3569bf2cd4095b210a232e0e46171006ad5f9d24..e8c36f41a7f18748163ccbf17ae3e94c3f4a1df0 100755 (executable)
@@ -641,6 +641,10 @@ def runtest_inner(test, verbose, quiet,
     refleak = False  # True if the test leaked references.
     try:
         save_stdout = sys.stdout
+        # Save various things that tests may mess up so we can restore
+        # them afterward.
+        save_environ = dict(os.environ)
+        save_argv = sys.argv[:]
         try:
             if capture_stdout:
                 sys.stdout = capture_stdout
@@ -663,6 +667,17 @@ def runtest_inner(test, verbose, quiet,
             test_time = time.time() - start_time
         finally:
             sys.stdout = save_stdout
+            # Restore what we saved if needed, but also complain if the test
+            # changed it so that the test may eventually get fixed.
+            if not os.environ == save_environ:
+                if not quiet:
+                    print "Warning: os.environ was modified by", test
+                os.environ.clear()
+                os.environ.update(save_environ)
+            if not sys.argv == save_argv:
+                if not quiet:
+                    print "Warning: argv was modified by", test
+                sys.argv[:] = save_argv
     except test_support.ResourceDenied, msg:
         if not quiet:
             print test, "skipped --", msg
index 2e052fa34fab99c857be4c6bf265e984c41f8cad..2b55de2caf74f0bd2e493d355149d7b8189fc036 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1436,6 +1436,9 @@ Extension Modules
 Tests
 -----
 
+- Issue #7058: Added save/restore for argv and os.environ to runtest_inner
+  in regrtest, with warnings if the called test modifies them.
+
 - Issue #7042: Fix test_signal (test_itimer_virtual) failure on OS X 10.6.
 
 - Issue #6806: test_platform failed under OS X 10.6.0 because ``sw_ver`` leaves