]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-34179: Make sure decimal context doesn't affect other tests. (GH-8376) (#8384)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 21 Jul 2018 18:38:49 +0000 (11:38 -0700)
committerStefan Krah <skrah@bytereef.org>
Sat, 21 Jul 2018 18:38:49 +0000 (20:38 +0200)
(cherry picked from commit 938045f335b52ddb47076e9fbe4229a33b4bd9be)

Co-authored-by: Bo Bayles <bbayles@gmail.com>
Lib/test/test_time.py

index 5b6e58fa55756eb29abf39b7544a0fa006e4c9e4..0e0e9065b741c80406ba1a59651791dc81d9a2b1 100644 (file)
@@ -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