Skip to content

Commit 1d12d28

Browse files
author
Rémi Lapeyre
committed
Move CalledProcessError pickling test to test_subprocess
1 parent 12dc912 commit 1d12d28

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Lib/test/test_exceptions.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,14 +1415,10 @@ def test_copy_pickle(self):
14151415

14161416
def test_pickle_overriden_init(self):
14171417
# Issue #27015
1418-
from subprocess import CalledProcessError
1419-
14201418
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
1421-
orig = CalledProcessError(returncode=2, cmd='foo')
1419+
orig = NaiveException(x='foo')
14221420
exc = pickle.loads(pickle.dumps(orig, proto))
1423-
self.assertEqual(orig.cmd, exc.cmd)
1424-
self.assertEqual(orig.returncode, exc.returncode)
1425-
1421+
self.assertEqual(orig.x, exc.x)
14261422

14271423

14281424
if __name__ == '__main__':

Lib/test/test_subprocess.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import threading
1919
import gc
2020
import textwrap
21+
import pickle
2122
from test.support import FakePath
2223

2324
try:
@@ -1690,6 +1691,14 @@ def test_CalledProcessError_str_non_zero(self):
16901691
error_string = str(err)
16911692
self.assertIn("non-zero exit status 2.", error_string)
16921693

1694+
def test_CalledProcessError_picklable(self):
1695+
# Issue #27015
1696+
err = subprocess.CalledProcessError(returncode=2, cmd='foo')
1697+
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
1698+
new = pickle.loads(pickle.dumps(err, proto))
1699+
self.assertEqual(err.returncode, new.returncode)
1700+
self.assertEqual(err.cmd, new.cmd)
1701+
16931702
def test_preexec(self):
16941703
# DISCLAIMER: Setting environment variables is *not* a good use
16951704
# of a preexec_fn. This is merely a test.

0 commit comments

Comments
 (0)