diff options
author | Tim Peters <tim.peters@gmail.com> | 2006-06-19 09:09:44 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2006-06-19 09:09:44 (GMT) |
commit | e7d7caa17a3f63732ded961629704283a5508662 (patch) | |
tree | 0042db31fec23e085491f720cbf626097c02dcff | |
parent | c314ac54928f331bce52b2834aceb666373ef340 (diff) | |
download | cpython-e7d7caa17a3f63732ded961629704283a5508662.zip cpython-e7d7caa17a3f63732ded961629704283a5508662.tar.gz cpython-e7d7caa17a3f63732ded961629704283a5508662.tar.bz2 |
TestHelp.make_parser(): This was making a permanent change to
os.environ (setting envar COLUMNS), which at least caused
test_float_default() to fail if the tests were run more than once.
This repairs the test_optparse -R failures Neal reported on
python-dev. It also explains some seemingly bizarre test_optparse
failures we saw a couple weeks ago on the buildbots, when
test_optparse failed due to test_file failing to clean up after
itself, and then test_optparse failed in an entirely different
way when regrtest's -w option ran test_optparse a second time.
It's now obvious that make_parser() permanently changing os.environ
was responsible for the second half of that.
-rw-r--r-- | Lib/test/test_optparse.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/test/test_optparse.py b/Lib/test/test_optparse.py index 622d757..9fcbe85 100644 --- a/Lib/test/test_optparse.py +++ b/Lib/test/test_optparse.py @@ -1460,8 +1460,19 @@ class TestHelp(BaseTest): make_option("--foo", action="append", type="string", dest='foo', help="store FOO in the foo list for later fooing"), ] + # The parser constructor looks at the COLUMNS envar. We need to + # restore the original value after the parser is constructed, else + # that's a permanent change possibly affecting other tests, and + # definitely affecting these tests when they're run multiple times. + orig_columns = os.environ.get('COLUMNS') os.environ['COLUMNS'] = str(columns) - return InterceptingOptionParser(option_list=options) + try: + return InterceptingOptionParser(option_list=options) + finally: + if orig_columns is None: + del os.environ['COLUMNS'] + else: + os.environ['COLUMNS'] = orig_columns def assertHelpEquals(self, expected_output): if type(expected_output) is types.UnicodeType: |