Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Restore decimal context after decimal doctests
The modified context caused tests failures in several other tests.
  • Loading branch information
serhiy-storchaka committed Jun 6, 2024
commit 6e4122f9222e160a55c7a02b00d17c13b89e7031
10 changes: 7 additions & 3 deletions Lib/test/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5892,13 +5892,17 @@ def load_tests(loader, tests, pattern):

if TODO_TESTS is None:
from doctest import DocTestSuite, IGNORE_EXCEPTION_DETAIL
orig_context = orig_sys_decimal.getcontext().copy()
for mod in C, P:
if not mod:
continue
def setUp(slf, mod=mod):
sys.modules['decimal'] = mod
def tearDown(slf):
init(mod)
def tearDown(slf, mod=mod):
sys.modules['decimal'] = orig_sys_decimal
mod.setcontext(ORIGINAL_CONTEXT[mod].copy())
orig_sys_decimal.setcontext(orig_context.copy())
optionflags = IGNORE_EXCEPTION_DETAIL if mod is C else 0
sys.modules['decimal'] = mod
tests.addTest(DocTestSuite(mod, setUp=setUp, tearDown=tearDown,
Expand All @@ -5913,8 +5917,8 @@ def setUpModule():
TEST_ALL = ARITH if ARITH is not None else is_resource_enabled('decimal')

def tearDownModule():
if C: C.setcontext(ORIGINAL_CONTEXT[C])
P.setcontext(ORIGINAL_CONTEXT[P])
if C: C.setcontext(ORIGINAL_CONTEXT[C].copy())
P.setcontext(ORIGINAL_CONTEXT[P].copy())
if not C:
warnings.warn('C tests skipped: no module named _decimal.',
UserWarning)
Expand Down