diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-04-14 14:43:03 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-04-14 14:43:03 (GMT) |
commit | 839e5eafcb351178983c2f603152091d03d60831 (patch) | |
tree | 76cc027b985bf4d504fa8440fb508fc3a0c8638f /Lib/test/test_os.py | |
parent | 6d10139d70b80cf1326c2763dd13ecc169ce1931 (diff) | |
download | cpython-839e5eafcb351178983c2f603152091d03d60831.zip cpython-839e5eafcb351178983c2f603152091d03d60831.tar.gz cpython-839e5eafcb351178983c2f603152091d03d60831.tar.bz2 |
Issue #17702: use assertRaises() for the unit test
Diffstat (limited to 'Lib/test/test_os.py')
-rw-r--r-- | Lib/test/test_os.py | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 83373be..33b9e5b 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -636,19 +636,13 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol): missing = 'missingkey' self.assertNotIn(missing, os.environ) - try: + with self.assertRaises(KeyError) as cm: os.environ[missing] - except KeyError as err: - self.assertIs(err.args[0], missing) - else: - self.fail("KeyError not raised") + self.assertIs(cm.exception.args[0], missing) - try: + with self.assertRaises(KeyError) as cm: del os.environ[missing] - except KeyError as err: - self.assertIs(err.args[0], missing) - else: - self.fail("KeyError not raised") + self.assertIs(cm.exception.args[0], missing) class WalkTests(unittest.TestCase): """Tests for os.walk().""" |