Index: Lib/test/regrtest.py =================================================================== --- Lib/test/regrtest.py (revision 75216) +++ Lib/test/regrtest.py (working copy) @@ -641,6 +633,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 capture_stdout: sys.stdout = capture_stdout @@ -663,6 +659,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 and not quiet: + 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