summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_time.py
diff options
context:
space:
mode:
authorBo Bayles <bbayles@gmail.com>2018-07-21 17:54:14 (GMT)
committerStefan Krah <skrah@bytereef.org>2018-07-21 17:54:14 (GMT)
commit938045f335b52ddb47076e9fbe4229a33b4bd9be (patch)
tree456626ea5e957748bd756acd9af82e210afd5213 /Lib/test/test_time.py
parent56868f940e0cc0b35d33c0070107ff3bed2d8766 (diff)
downloadcpython-938045f335b52ddb47076e9fbe4229a33b4bd9be.zip
cpython-938045f335b52ddb47076e9fbe4229a33b4bd9be.tar.gz
cpython-938045f335b52ddb47076e9fbe4229a33b4bd9be.tar.bz2
bpo-34179: Make sure decimal context doesn't affect other tests. (#8376)
Diffstat (limited to 'Lib/test/test_time.py')
-rw-r--r--Lib/test/test_time.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index cab437d..7354b96 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -872,19 +872,19 @@ class CPyTimeTestCase:
ns_timestamps = self._rounding_values(use_float)
valid_values = convert_values(ns_timestamps)
for time_rnd, decimal_rnd in ROUNDING_MODES :
- context = decimal.getcontext()
- context.rounding = decimal_rnd
-
- for value in valid_values:
- debug_info = {'value': value, 'rounding': decimal_rnd}
- try:
- result = pytime_converter(value, time_rnd)
- expected = expected_func(value)
- except Exception as exc:
- self.fail("Error on timestamp conversion: %s" % debug_info)
- self.assertEqual(result,
- expected,
- debug_info)
+ with decimal.localcontext() as context:
+ context.rounding = decimal_rnd
+
+ for value in valid_values:
+ debug_info = {'value': value, 'rounding': decimal_rnd}
+ try:
+ result = pytime_converter(value, time_rnd)
+ expected = expected_func(value)
+ except Exception as exc:
+ self.fail("Error on timestamp conversion: %s" % debug_info)
+ self.assertEqual(result,
+ expected,
+ debug_info)
# test overflow
ns = self.OVERFLOW_SECONDS * SEC_TO_NS