Skip to content

Commit 9c13670

Browse files
miss-islingtonbbayles
authored andcommitted
bpo-34179: Make sure decimal context doesn't affect other tests. (GH-8376) (#8384)
(cherry picked from commit 938045f) Co-authored-by: Bo Bayles <[email protected]>
1 parent 916bcc6 commit 9c13670

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Lib/test/test_time.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -772,19 +772,19 @@ def convert_values(ns_timestamps):
772772
ns_timestamps = self._rounding_values(use_float)
773773
valid_values = convert_values(ns_timestamps)
774774
for time_rnd, decimal_rnd in ROUNDING_MODES :
775-
context = decimal.getcontext()
776-
context.rounding = decimal_rnd
777-
778-
for value in valid_values:
779-
debug_info = {'value': value, 'rounding': decimal_rnd}
780-
try:
781-
result = pytime_converter(value, time_rnd)
782-
expected = expected_func(value)
783-
except Exception as exc:
784-
self.fail("Error on timestamp conversion: %s" % debug_info)
785-
self.assertEqual(result,
786-
expected,
787-
debug_info)
775+
with decimal.localcontext() as context:
776+
context.rounding = decimal_rnd
777+
778+
for value in valid_values:
779+
debug_info = {'value': value, 'rounding': decimal_rnd}
780+
try:
781+
result = pytime_converter(value, time_rnd)
782+
expected = expected_func(value)
783+
except Exception as exc:
784+
self.fail("Error on timestamp conversion: %s" % debug_info)
785+
self.assertEqual(result,
786+
expected,
787+
debug_info)
788788

789789
# test overflow
790790
ns = self.OVERFLOW_SECONDS * SEC_TO_NS

0 commit comments

Comments
 (0)