Skip to content

Commit dbbb043

Browse files
authored
Display exception name when subprocesses raise them (#3450)
1 parent 343fe92 commit dbbb043

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

docs/changelog/3450.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Log exception name when subprocess execution produces one.
2+
3+
- by :user:`ssbarnea`

src/tox/execute/local_sub_process/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ def __enter__(self) -> ExecuteStatus:
214214
env=self.request.env,
215215
)
216216
except OSError as exception:
217+
# We log a nice error message to avout returning opaque error codes,
218+
# like exit code 2 (filenotfound).
219+
logging.error("Exception running subprocess %s", str(exception)) # noqa: TRY400
217220
return LocalSubprocessExecuteFailedStatus(self.options, self._out, self._err, exception.errno)
218221

219222
status = LocalSubprocessExecuteStatus(self.options, self._out, self._err, process)

tests/execute/local_subprocess/test_local_subprocess.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import locale
55
import logging
66
import os
7+
import re
78
import shutil
89
import stat
910
import subprocess
@@ -264,7 +265,11 @@ def test_command_does_not_exist(caplog: LogCaptureFixture, os_env: dict[str, str
264265
assert outcome.exit_code != Outcome.OK
265266
assert not outcome.out
266267
assert not outcome.err
267-
assert not caplog.records
268+
assert len(caplog.records) == 1
269+
assert caplog.records[0].levelname == "ERROR"
270+
assert re.match(
271+
r".*(No such file or directory|The system cannot find the file specified).*", caplog.records[0].message
272+
)
268273

269274

270275
@pytest.mark.skipif(sys.platform == "win32", reason="You need a conhost shell for keyboard interrupt")

0 commit comments

Comments
 (0)