Skip to content

Commit 6e4122f

Browse files
Restore decimal context after decimal doctests
The modified context caused tests failures in several other tests.
1 parent f878d46 commit 6e4122f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Lib/test/test_decimal.py

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

58935893
if TODO_TESTS is None:
58945894
from doctest import DocTestSuite, IGNORE_EXCEPTION_DETAIL
5895+
orig_context = orig_sys_decimal.getcontext().copy()
58955896
for mod in C, P:
58965897
if not mod:
58975898
continue
58985899
def setUp(slf, mod=mod):
58995900
sys.modules['decimal'] = mod
5900-
def tearDown(slf):
5901+
init(mod)
5902+
def tearDown(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_DETAIL if mod is C else 0
59035907
sys.modules['decimal'] = mod
59045908
tests.addTest(DocTestSuite(mod, setUp=setUp, tearDown=tearDown,
@@ -5913,8 +5917,8 @@ def setUpModule():
59135917
TEST_ALL = ARITH if ARITH is not None else is_resource_enabled('decimal')
59145918

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

0 commit comments

Comments
 (0)