From: Bo Bayles Date: Sat, 21 Jul 2018 17:54:14 +0000 (-0500) Subject: bpo-34179: Make sure decimal context doesn't affect other tests. (#8376) X-Git-Tag: v3.8.0a1~1346 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=938045f335b52ddb47076e9fbe4229a33b4bd9be;p=thirdparty%2FPython%2Fcpython.git bpo-34179: Make sure decimal context doesn't affect other tests. (#8376) --- diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index cab437d44ad7..7354b969907b 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