diff --git a/plumbum/commands/processes.py b/plumbum/commands/processes.py index 3ecc13e97..678ce0b15 100644 --- a/plumbum/commands/processes.py +++ b/plumbum/commands/processes.py @@ -113,7 +113,9 @@ class ProcessExecutionError(EnvironmentError): well as the command line used to create the process (``argv``) """ - def __init__(self, argv, retcode, stdout, stderr, message=None, host=None): + def __init__( + self, argv, retcode, stdout=None, stderr=None, message=None, host=None + ): # we can't use 'super' here since EnvironmentError only keeps the first 2 args, # which leads to failuring in loading this object from a pickle.dumps. @@ -144,7 +146,7 @@ def __init__(self, argv, retcode, stdout, stderr, message=None, host=None): self.all_output += ["\nStderr: | ", stderr] def _format_lines(self, lines): - fd_names = ['stdout', 'stderr'] + fd_names = ["stdout", "stderr"] for idx, ts, stream_fd, line in lines: source = fd_names[stream_fd - 1] for _line in line.splitlines(): @@ -399,7 +401,7 @@ def iter_lines( ret[t] = line yield tuple(ret) elif mode is BY_TYPE: - yield (stream_fd), line + yield (stream_fd), line # this will take care of checking return code and timeouts _check_process(proc, retcode, timeout, *buffers) diff --git a/tests/test_local.py b/tests/test_local.py index 448ce0b35..e2d58cd80 100644 --- a/tests/test_local.py +++ b/tests/test_local.py @@ -731,10 +731,15 @@ def test_exceptions(self): def test_exception_pickling(self): import pickle + with pytest.raises(ProcessExecutionError) as exc_info: local.cmd.ls("no-file") assert pickle.loads(pickle.dumps(exc_info.value)).argv == exc_info.value.argv + with pytest.raises(ProcessExecutionError) as exc_info: + list(local.cmd.ls["no-file"].popen()) + assert pickle.loads(pickle.dumps(exc_info.value)).argv == exc_info.value.argv + def test_tempdir(self): with local.tempdir() as dir: assert dir.is_dir()