diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-07-21 18:38:49 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2018-07-21 18:38:49 (GMT) |
commit | 9c136700aa1f755fa2ea64594688a0930b716597 (patch) | |
tree | c522df3e17c0cea07a75ae0ae056e6bc1b5ec6c2 | |
parent | 916bcc6fde2db95199454b22f608648467fbbc54 (diff) | |
download | cpython-9c136700aa1f755fa2ea64594688a0930b716597.zip cpython-9c136700aa1f755fa2ea64594688a0930b716597.tar.gz cpython-9c136700aa1f755fa2ea64594688a0930b716597.tar.bz2 |
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@gmail.com>
-rw-r--r-- | Lib/test/test_time.py | 26 |
1 files 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 |