Skip to content

Commit e5b149e

Browse files
Fix test_decimal and test_xml_etree.
1 parent 9bd77bc commit e5b149e

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

Lib/test/test_decimal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
C = import_fresh_module('decimal', fresh=['_decimal'])
6464
P = import_fresh_module('decimal', blocked=['_decimal'])
65-
orig_sys_decimal = sys.modules['decimal']
65+
import decimal as orig_sys_decimal
6666

6767
# fractions module must import the correct decimal module.
6868
cfractions = import_fresh_module('fractions', fresh=['fractions'])

Lib/test/test_xml_etree.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from test import support
2727
from test.support import os_helper
2828
from test.support import warnings_helper
29-
from test.support import findfile, gc_collect, swap_attr
29+
from test.support import findfile, gc_collect, swap_attr, swap_item
3030
from test.support.import_helper import import_fresh_module
3131
from test.support.os_helper import TESTFN
3232

@@ -167,21 +167,18 @@ def setUpClass(cls):
167167
cls.modules = {pyET, ET}
168168

169169
def pickleRoundTrip(self, obj, name, dumper, loader, proto):
170-
save_m = sys.modules[name]
171170
try:
172-
sys.modules[name] = dumper
173-
temp = pickle.dumps(obj, proto)
174-
sys.modules[name] = loader
175-
result = pickle.loads(temp)
171+
with swap_item(sys.modules, name, dumper):
172+
temp = pickle.dumps(obj, proto)
173+
with swap_item(sys.modules, name, loader):
174+
result = pickle.loads(temp)
176175
except pickle.PicklingError as pe:
177176
# pyET must be second, because pyET may be (equal to) ET.
178177
human = dict([(ET, "cET"), (pyET, "pyET")])
179178
raise support.TestFailed("Failed to round-trip %r from %r to %r"
180179
% (obj,
181180
human.get(dumper, dumper),
182181
human.get(loader, loader))) from pe
183-
finally:
184-
sys.modules[name] = save_m
185182
return result
186183

187184
def assertEqualElements(self, alice, bob):

0 commit comments

Comments
 (0)