mirror of https://github.com/python/cpython.git
Restore decimal context after decimal doctests (GH-120149)
The modified context caused tests failures in several other tests.
This commit is contained in:
parent
d50a7c478f
commit
2d7ff6e0e7
|
@ -5892,13 +5892,17 @@ def load_tests(loader, tests, pattern):
|
||||||
|
|
||||||
if TODO_TESTS is None:
|
if TODO_TESTS is None:
|
||||||
from doctest import DocTestSuite, IGNORE_EXCEPTION_DETAIL
|
from doctest import DocTestSuite, IGNORE_EXCEPTION_DETAIL
|
||||||
|
orig_context = orig_sys_decimal.getcontext().copy()
|
||||||
for mod in C, P:
|
for mod in C, P:
|
||||||
if not mod:
|
if not mod:
|
||||||
continue
|
continue
|
||||||
def setUp(slf, mod=mod):
|
def setUp(slf, mod=mod):
|
||||||
sys.modules['decimal'] = mod
|
sys.modules['decimal'] = mod
|
||||||
def tearDown(slf):
|
init(mod)
|
||||||
|
def tearDown(slf, mod=mod):
|
||||||
sys.modules['decimal'] = orig_sys_decimal
|
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
|
optionflags = IGNORE_EXCEPTION_DETAIL if mod is C else 0
|
||||||
sys.modules['decimal'] = mod
|
sys.modules['decimal'] = mod
|
||||||
tests.addTest(DocTestSuite(mod, setUp=setUp, tearDown=tearDown,
|
tests.addTest(DocTestSuite(mod, setUp=setUp, tearDown=tearDown,
|
||||||
|
@ -5913,8 +5917,8 @@ def setUpModule():
|
||||||
TEST_ALL = ARITH if ARITH is not None else is_resource_enabled('decimal')
|
TEST_ALL = ARITH if ARITH is not None else is_resource_enabled('decimal')
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
if C: C.setcontext(ORIGINAL_CONTEXT[C])
|
if C: C.setcontext(ORIGINAL_CONTEXT[C].copy())
|
||||||
P.setcontext(ORIGINAL_CONTEXT[P])
|
P.setcontext(ORIGINAL_CONTEXT[P].copy())
|
||||||
if not C:
|
if not C:
|
||||||
warnings.warn('C tests skipped: no module named _decimal.',
|
warnings.warn('C tests skipped: no module named _decimal.',
|
||||||
UserWarning)
|
UserWarning)
|
||||||
|
|
Loading…
Reference in New Issue