summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-06 17:36:46 (GMT)
committerGitHub <noreply@github.com>2024-06-06 17:36:46 (GMT)
commit015ddfeca5e39a3796ee144d07accb1d5c7e7522 (patch)
tree7a84e4da64aab3e32d068d652a15acdb5b162463 /Lib
parentfbdff3803af23f632469933e33ee735f853bbdec (diff)
downloadcpython-015ddfeca5e39a3796ee144d07accb1d5c7e7522.zip
cpython-015ddfeca5e39a3796ee144d07accb1d5c7e7522.tar.gz
cpython-015ddfeca5e39a3796ee144d07accb1d5c7e7522.tar.bz2
[3.13] Restore decimal context after decimal doctests (GH-120149) (GH-120167)
The modified context caused tests failures in several other tests. (cherry picked from commit 2d7ff6e0e7d4c08ba84079a5c19a4a485626e1de) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_decimal.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index e927e24..4675510 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -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,
@@ -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)