diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2025-10-21 21:11:44 +0200 |
|---|---|---|
| committer | Natalia <124304+nessita@users.noreply.github.com> | 2025-10-22 15:21:29 -0300 |
| commit | c361494cbb134540f2f35a6364ea9259f0084a58 (patch) | |
| tree | 76c495f6244cc2c5a3265ef4494de08b7636616b | |
| parent | a6294d7d26536f37d08d39e2d607cc49eaff8435 (diff) | |
[5.1.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
52188a5ca6bafea0a66f17baacb315d61c7b99cd without skipping it.
Backport of 548209e620b3ca34396a360453f07c8dbb8aa6c7 from main.
| -rw-r--r-- | tests/test_runner/test_parallel.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/test_runner/test_parallel.py b/tests/test_runner/test_parallel.py index 73ef480cc1..04890b5b86 100644 --- a/tests/test_runner/test_parallel.py +++ b/tests/test_runner/test_parallel.py @@ -21,6 +21,12 @@ class ExceptionThatFailsUnpickling(Exception): def __init__(self, arg): super().__init__() + def __reduce__(self): + # tblib 3.2+ makes exception subclasses picklable by default. + # Return (cls, ()) so the constructor fails on unpickle, preserving + # the needed behavior for test_pickle_errors_detection. + return (self.__class__, ()) + class ParallelTestRunnerTest(SimpleTestCase): """ @@ -109,6 +115,8 @@ class RemoteTestResultTest(SimpleTestCase): result = RemoteTestResult() result._confirm_picklable(picklable_error) + # The exception can be pickled but not unpickled. + pickle.dumps(not_unpicklable_error) msg = "__init__() missing 1 required positional argument" with self.assertRaisesMessage(TypeError, msg): result._confirm_picklable(not_unpicklable_error) |
