From 80e982f5adf1ca9f5aa11e8c3e74eee4c96302e7 Mon Sep 17 00:00:00 2001 From: Bo Bayles Date: Sat, 21 Jul 2018 09:20:32 -0500 Subject: [PATCH 1/3] Make sure decimal context doesn't affect other tests --- 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 cab437d44ad7de..7354b969907b16 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -872,19 +872,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 From d1b6de7ea8dbdece3b4041928fc3af8cff6c61d7 Mon Sep 17 00:00:00 2001 From: Bo Bayles Date: Sat, 21 Jul 2018 09:21:34 -0500 Subject: [PATCH 2/3] Add NEWS entry --- Misc/NEWS.d/next/Tests/2018-07-21-09-21-23.bpo-34179.Rq9ZOc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tests/2018-07-21-09-21-23.bpo-34179.Rq9ZOc.rst diff --git a/Misc/NEWS.d/next/Tests/2018-07-21-09-21-23.bpo-34179.Rq9ZOc.rst b/Misc/NEWS.d/next/Tests/2018-07-21-09-21-23.bpo-34179.Rq9ZOc.rst new file mode 100644 index 00000000000000..e66c7b7f74e086 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2018-07-21-09-21-23.bpo-34179.Rq9ZOc.rst @@ -0,0 +1 @@ +Use decimal.localcontext for test_time to avoid affecting other tests From 9143b2a58f3d207a08f250afbc7d8c12942e8cb8 Mon Sep 17 00:00:00 2001 From: Bo Bayles Date: Sat, 21 Jul 2018 11:11:39 -0500 Subject: [PATCH 3/3] Revert "Add NEWS entry" This reverts commit d1b6de7ea8dbdece3b4041928fc3af8cff6c61d7. --- Misc/NEWS.d/next/Tests/2018-07-21-09-21-23.bpo-34179.Rq9ZOc.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Misc/NEWS.d/next/Tests/2018-07-21-09-21-23.bpo-34179.Rq9ZOc.rst diff --git a/Misc/NEWS.d/next/Tests/2018-07-21-09-21-23.bpo-34179.Rq9ZOc.rst b/Misc/NEWS.d/next/Tests/2018-07-21-09-21-23.bpo-34179.Rq9ZOc.rst deleted file mode 100644 index e66c7b7f74e086..00000000000000 --- a/Misc/NEWS.d/next/Tests/2018-07-21-09-21-23.bpo-34179.Rq9ZOc.rst +++ /dev/null @@ -1 +0,0 @@ -Use decimal.localcontext for test_time to avoid affecting other tests