From 938045f335b52ddb47076e9fbe4229a33b4bd9be Mon Sep 17 00:00:00 2001 From: Bo Bayles Date: Sat, 21 Jul 2018 12:54:14 -0500 Subject: [PATCH] bpo-34179: Make sure decimal context doesn't affect other tests. (#8376) --- Lib/test/test_time.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index cab437d44ad..7354b969907 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 + 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) + 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