We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b500563 commit 5841c2cCopy full SHA for 5841c2c
1 file changed
Lib/test/test_json/test_fail.py
@@ -251,18 +251,14 @@ def __call__(self, *args):
251
return ValueError("boom")
252
253
hook = Trigger()
254
- try:
255
- json.JSONDecodeError = hook
256
- json.decoder.JSONDecodeError = hook
257
-
+ with (
+ support.swap_attr(json, "JSONDecodeError", hook),
+ support.swap_attr(json.decoder, "JSONDecodeError", hook)
+ ):
258
# The exact exception type is not important here;
259
# this test only ensures we don't crash.
260
with self.assertRaises(Exception):
261
json.loads('"\\uZZZZ"')
262
263
- finally:
264
- json.JSONDecodeError = orig_json_error
265
- json.decoder.JSONDecodeError = orig_decoder_error
266
267
class TestPyFail(TestFail, PyTest): pass
268
class TestCFail(TestFail, CTest): pass
0 commit comments