]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-34179: Make sure decimal context doesn't affect other tests. (#8376)
authorBo Bayles <bbayles@gmail.com>
Sat, 21 Jul 2018 17:54:14 +0000 (12:54 -0500)
committerStefan Krah <skrah@bytereef.org>
Sat, 21 Jul 2018 17:54:14 +0000 (19:54 +0200)
Lib/test/test_time.py

index cab437d44ad7dee6affe3edbabd52a6b4f1b21df..7354b969907b16a4c4b629d95e990d4196ad0388 100644 (file)
@@ -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