[Python-checkins] bpo-34179: Make sure decimal context doesn't affect other tests. (GH-8376) (#8384)

Stefan Krah webhook-mailer at python.org
Sat Jul 21 14:38:51 EDT 2018


https://github.com/python/cpython/commit/9c136700aa1f755fa2ea64594688a0930b716597
commit: 9c136700aa1f755fa2ea64594688a0930b716597
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Stefan Krah <skrah at bytereef.org>
date: 2018-07-21T20:38:49+02:00
summary:

bpo-34179:  Make sure decimal context doesn't affect other tests.  (GH-8376) (#8384)

(cherry picked from commit 938045f335b52ddb47076e9fbe4229a33b4bd9be)

Co-authored-by: Bo Bayles <bbayles at gmail.com>

files:
M Lib/test/test_time.py

diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index 5b6e58fa5575..0e0e9065b741 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -772,19 +772,19 @@ def convert_values(ns_timestamps):
         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



More information about the Python-checkins mailing list