Skip to content

Commit b03d71d

Browse files
[3.12] Restore decimal context after decimal doctests (GH-120149) (GH-120168)
The modified context caused tests failures in several other tests. (cherry picked from commit 2d7ff6e) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 94eee78 commit b03d71d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Lib/test/test_decimal.py

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

59255925
if TODO_TESTS is None:
59265926
from doctest import DocTestSuite, IGNORE_EXCEPTION_DETAIL
5927+
orig_context = orig_sys_decimal.getcontext().copy()
59275928
for mod in C, P:
59285929
if not mod:
59295930
continue
59305931
def setUp(slf, mod=mod):
59315932
sys.modules['decimal'] = mod
5932-
def tearDown(slf):
5933+
init(mod)
5934+
def tearDown(slf, mod=mod):
59335935
sys.modules['decimal'] = orig_sys_decimal
5936+
mod.setcontext(ORIGINAL_CONTEXT[mod].copy())
5937+
orig_sys_decimal.setcontext(orig_context.copy())
59345938
optionflags = IGNORE_EXCEPTION_DETAIL if mod is C else 0
59355939
sys.modules['decimal'] = mod
59365940
tests.addTest(DocTestSuite(mod, setUp=setUp, tearDown=tearDown,
@@ -5945,8 +5949,8 @@ def setUpModule():
59455949
TEST_ALL = ARITH if ARITH is not None else is_resource_enabled('decimal')
59465950

59475951
def tearDownModule():
5948-
if C: C.setcontext(ORIGINAL_CONTEXT[C])
5949-
P.setcontext(ORIGINAL_CONTEXT[P])
5952+
if C: C.setcontext(ORIGINAL_CONTEXT[C].copy())
5953+
P.setcontext(ORIGINAL_CONTEXT[P].copy())
59505954
if not C:
59515955
warnings.warn('C tests skipped: no module named _decimal.',
59525956
UserWarning)

0 commit comments

Comments
 (0)