From 9c136700aa1f755fa2ea64594688a0930b716597 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Sat, 21 Jul 2018 11:38:49 -0700 Subject: bpo-34179: Make sure decimal context doesn't affect other tests. (GH-8376) (#8384) (cherry picked from commit 938045f335b52ddb47076e9fbe4229a33b4bd9be) Co-authored-by: Bo Bayles --- Lib/test/test_time.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index 5b6e58f..0e0e906 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -772,19 +772,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 -- cgit v0.12