Skip to content

Commit 3c75f48

Browse files
Use enterClassContext().
1 parent 66a19ef commit 3c75f48

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

Lib/test/test_xpickle.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ def have_python_version(py_version):
8585
@support.requires_resource('cpu')
8686
class AbstractCompatTests(pickletester.AbstractPickleTests):
8787
py_version = None
88-
_OLD_HIGHEST_PROTOCOL = pickle.HIGHEST_PROTOCOL
8988

9089
@classmethod
9190
def setUpClass(cls):
@@ -96,14 +95,10 @@ def setUpClass(cls):
9695
# Override the default pickle protocol to match what xpickle worker
9796
# will be running.
9897
highest_protocol = highest_proto_for_py_version(cls.py_version)
99-
pickletester.protocols = range(highest_protocol + 1)
100-
pickle.HIGHEST_PROTOCOL = highest_protocol
101-
102-
@classmethod
103-
def tearDownClass(cls):
104-
# Set the highest protocol back to the default.
105-
pickle.HIGHEST_PROTOCOL = cls._OLD_HIGHEST_PROTOCOL
106-
pickletester.protocols = range(pickle.HIGHEST_PROTOCOL + 1)
98+
cls.enterClassContext(support.swap_attr(pickletester, 'protocols',
99+
range(highest_protocol + 1)))
100+
cls.enterClassContext(support.swap_attr(pickle, 'HIGHEST_PROTOCOL',
101+
highest_protocol))
107102

108103
@staticmethod
109104
def send_to_worker(python, data):

0 commit comments

Comments
 (0)