diff options
Diffstat (limited to 'Lib/test/test_getopt.py')
-rw-r--r-- | Lib/test/test_getopt.py | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/Lib/test/test_getopt.py b/Lib/test/test_getopt.py index 11ae163..b7a6309 100644 --- a/Lib/test/test_getopt.py +++ b/Lib/test/test_getopt.py @@ -1,7 +1,7 @@ # test_getopt.py # David Goodger <dgoodger@bigfoot.com> 2000-08-19 -from test.support import verbose, run_doctest, run_unittest +from test.support import verbose, run_doctest, run_unittest, EnvironmentVarGuard import unittest import getopt @@ -11,15 +11,13 @@ sentinel = object() class GetoptTests(unittest.TestCase): def setUp(self): - self.old_posixly_correct = os.environ.get("POSIXLY_CORRECT", sentinel) - if self.old_posixly_correct is not sentinel: - del os.environ["POSIXLY_CORRECT"] + self.env = EnvironmentVarGuard() + if "POSIXLY_CORRECT" in self.env: + del self.env["POSIXLY_CORRECT"] def tearDown(self): - if self.old_posixly_correct is sentinel: - os.environ.pop("POSIXLY_CORRECT", None) - else: - os.environ["POSIXLY_CORRECT"] = self.old_posixly_correct + self.env.__exit__() + del self.env def assertError(self, *args, **kwargs): self.assertRaises(getopt.GetoptError, *args, **kwargs) @@ -135,7 +133,7 @@ class GetoptTests(unittest.TestCase): self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2']) # Posix style via POSIXLY_CORRECT - os.environ["POSIXLY_CORRECT"] = "1" + self.env["POSIXLY_CORRECT"] = "1" opts, args = getopt.gnu_getopt(cmdline, 'ab:', ['alpha', 'beta=']) self.assertEqual(opts, [('-a', '')]) self.assertEqual(args, ['arg1', '-b', '1', '--alpha', '--beta=2']) |