Print return code when subprocess fails (MR 2161)
It can be very useful to figure out why a particular subprocess might be failing ;)
This commit is contained in:
parent
ff0942b12d
commit
36aabcc4fe
|
@ -216,7 +216,8 @@ def check_return_code(args, code, log_message):
|
|||
logging.debug("^" * 70)
|
||||
logging.info("NOTE: The failed command's output is above the ^^^ line"
|
||||
" in the log file: " + args.log)
|
||||
raise RuntimeError("Command failed: " + log_message)
|
||||
raise RuntimeError(f"Command failed (exit code {str(code)}): " +
|
||||
log_message)
|
||||
|
||||
|
||||
def sudo_timer_iterate():
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# Copyright 2022 Oliver Smith
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
""" Test pmb.helpers.run_core """
|
||||
import re
|
||||
import sys
|
||||
import subprocess
|
||||
import pytest
|
||||
|
@ -146,13 +147,13 @@ def test_core(args):
|
|||
# Check the return code
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
func(args, msg, ["false"], output="log")
|
||||
assert str(e.value).startswith("Command failed:")
|
||||
assert re.search(r"^Command failed \(exit code -?\d*\): ", str(e.value))
|
||||
|
||||
# Kill with timeout
|
||||
args.timeout = 0.2
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
func(args, msg, ["sleep", "1"], output="log")
|
||||
assert str(e.value).startswith("Command failed:")
|
||||
assert re.search(r"^Command failed \(exit code -?\d*\): ", str(e.value))
|
||||
|
||||
|
||||
@pytest.mark.skip_ci
|
||||
|
|
Loading…
Reference in New Issue