Skip to content

Commit cd3b21b

Browse files
felixxmnessita
authored andcommitted
[4.2.x] Made RemoteTestResultTest.test_pickle_errors_detection() compatible with tblib 3.2+.
tblib 3.2+ makes exception subclasses with __init__() and the default __reduce__() picklable. This broke the test for RemoteTestResult._confirm_picklable(), which expects a specific exception to fail unpickling. https://github.com/ionelmc/python-tblib/blob/master/CHANGELOG.rst#320-2025-10-21 This fix defines ExceptionThatFailsUnpickling.__reduce__() in a way that pickle.dumps(obj) succeeds, but pickle.loads(pickle.dumps(obj)) raises TypeError. Refs #27301. This preserves the intent of the regression test from 52188a5 without skipping it. Backport of 548209e from main.
1 parent 321af48 commit cd3b21b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tests/test_runner/test_parallel.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class ExceptionThatFailsUnpickling(Exception):
2121
def __init__(self, arg):
2222
super().__init__()
2323

24+
def __reduce__(self):
25+
# tblib 3.2+ makes exception subclasses picklable by default.
26+
# Return (cls, ()) so the constructor fails on unpickle, preserving
27+
# the needed behavior for test_pickle_errors_detection.
28+
return (self.__class__, ())
29+
2430

2531
class ParallelTestRunnerTest(SimpleTestCase):
2632
"""
@@ -102,6 +108,8 @@ def test_pickle_errors_detection(self):
102108
result = RemoteTestResult()
103109
result._confirm_picklable(picklable_error)
104110

111+
# The exception can be pickled but not unpickled.
112+
pickle.dumps(not_unpicklable_error)
105113
msg = "__init__() missing 1 required positional argument"
106114
with self.assertRaisesMessage(TypeError, msg):
107115
result._confirm_picklable(not_unpicklable_error)

0 commit comments

Comments
 (0)