Skip to content

Commit 2d7ff6e

Browse files
Restore decimal context after decimal doctests (GH-120149)
The modified context caused tests failures in several other tests.
1 parent d50a7c4 commit 2d7ff6e

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎Lib/test/test_decimal.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5892,13 +5892,17 @@ def load_tests(loader, tests, pattern):
58925892

58935893
ifTODO_TESTSisNone:
58945894
fromdoctestimportDocTestSuite, IGNORE_EXCEPTION_DETAIL
5895+
orig_context=orig_sys_decimal.getcontext().copy()
58955896
formodinC, P:
58965897
ifnotmod:
58975898
continue
58985899
defsetUp(slf, mod=mod):
58995900
sys.modules['decimal'] =mod
5900-
deftearDown(slf):
5901+
init(mod)
5902+
deftearDown(slf, mod=mod):
59015903
sys.modules['decimal'] =orig_sys_decimal
5904+
mod.setcontext(ORIGINAL_CONTEXT[mod].copy())
5905+
orig_sys_decimal.setcontext(orig_context.copy())
59025906
optionflags=IGNORE_EXCEPTION_DETAILifmodisCelse0
59035907
sys.modules['decimal'] =mod
59045908
tests.addTest(DocTestSuite(mod, setUp=setUp, tearDown=tearDown,
@@ -5913,8 +5917,8 @@ def setUpModule():
59135917
TEST_ALL=ARITHifARITHisnotNoneelseis_resource_enabled('decimal')
59145918

59155919
deftearDownModule():
5916-
ifC: C.setcontext(ORIGINAL_CONTEXT[C])
5917-
P.setcontext(ORIGINAL_CONTEXT[P])
5920+
ifC: C.setcontext(ORIGINAL_CONTEXT[C].copy())
5921+
P.setcontext(ORIGINAL_CONTEXT[P].copy())
59185922
ifnotC:
59195923
warnings.warn('C tests skipped: no module named _decimal.',
59205924
UserWarning)

0 commit comments

Comments
 (0)