]> granicus.if.org Git - python/commitdiff
avoid fragility: make sure POSIXLY_CORRECT is completely controlled
authorFred Drake <fdrake@acm.org>
Tue, 3 Aug 2004 15:54:45 +0000 (15:54 +0000)
committerFred Drake <fdrake@acm.org>
Tue, 3 Aug 2004 15:54:45 +0000 (15:54 +0000)
for the tests, and restored properly when done

Lib/test/test_getopt.py

index da535939d04ad692952c129671fe038999de5c39..9856a6a70b233cacb007909c5e68b76d1ef0e523 100644 (file)
@@ -16,6 +16,10 @@ def expectException(teststr, expected, failure=AssertionError):
     else:
         raise failure
 
+old_posixly_correct = os.environ.get("POSIXLY_CORRECT")
+if old_posixly_correct is not None:
+    del os.environ["POSIXLY_CORRECT"]
+
 if verbose:
     print 'Running tests on getopt.short_has_arg'
 verify(getopt.short_has_arg('a', 'a:'))
@@ -124,7 +128,12 @@ os.environ["POSIXLY_CORRECT"] = "1"
 opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta='])
 verify(opts == [('-a', '')])
 verify(args == ['arg1', '-b', '1', '--alpha', '--beta=2'])
-del os.environ["POSIXLY_CORRECT"] 
+
+
+if old_posixly_correct is None:
+    del os.environ["POSIXLY_CORRECT"]
+else:
+    os.environ["POSIXLY_CORRECT"] = old_posixly_correct
 
 #------------------------------------------------------------------------------