Skip to content

Commit 5841c2c

Browse files
Update Lib/test/test_json/test_fail.py
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent b500563 commit 5841c2c

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

Lib/test/test_json/test_fail.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,14 @@ def __call__(self, *args):
251251
return ValueError("boom")
252252

253253
hook = Trigger()
254-
try:
255-
json.JSONDecodeError = hook
256-
json.decoder.JSONDecodeError = hook
257-
254+
with (
255+
support.swap_attr(json, "JSONDecodeError", hook),
256+
support.swap_attr(json.decoder, "JSONDecodeError", hook)
257+
):
258258
# The exact exception type is not important here;
259259
# this test only ensures we don't crash.
260260
with self.assertRaises(Exception):
261261
json.loads('"\\uZZZZ"')
262262

263-
finally:
264-
json.JSONDecodeError = orig_json_error
265-
json.decoder.JSONDecodeError = orig_decoder_error
266-
267263
class TestPyFail(TestFail, PyTest): pass
268264
class TestCFail(TestFail, CTest): pass

0 commit comments

Comments
 (0)