[Python-checkins] r75279 - in python/branches/py3k: Lib/test/regrtest.py Misc/NEWS

r.david.murray python-checkins at python.org
Thu Oct 8 01:39:00 CEST 2009


Author: r.david.murray
Date: Thu Oct  8 01:38:55 2009
New Revision: 75279

Log:
Merged revisions 75255 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r75255 | r.david.murray | 2009-10-05 13:03:09 -0400 (Mon, 05 Oct 2009) | 3 lines
  
  Issue #7058: Added save/restore for argv and os.environ to runtest_inner
  in regrtest, with warnings if the called test modifies them.
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/test/regrtest.py
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Lib/test/regrtest.py
==============================================================================
--- python/branches/py3k/Lib/test/regrtest.py	(original)
+++ python/branches/py3k/Lib/test/regrtest.py	Thu Oct  8 01:38:55 2009
@@ -682,6 +682,10 @@
     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 test.startswith('test.'):
                 abstest = test
@@ -702,6 +706,17 @@
             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 support.ResourceDenied as msg:
         if not quiet:
             print(test, "skipped --", msg)

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Thu Oct  8 01:38:55 2009
@@ -260,6 +260,9 @@
 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.
 
 - Fixed tests in importlib.test.source.test_abc_loader that were masking


More information about the Python-checkins mailing list