From 726832895de0e8d98fea8dde422e46b249a7bcc9 Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Wed, 1 Mar 2017 12:07:44 +0000 Subject: oeqa: add output to subprocess exceptions Out of the box subprocess.CalledProcessError.__str__() just displays the command and exit code, which isn't very useful for debugging. Add a function to oeqa.utils.subprocesstweak to monkey-patch __str__() so that it can also display the value of stdout and stderr. (From OE-Core rev: c55401ba1646202fa36e4973b05dbacaa146cb16) Signed-off-by: Ross Burton Signed-off-by: Richard Purdie --- meta/lib/oeqa/oetest.py | 9 --------- meta/lib/oeqa/utils/subprocesstweak.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 meta/lib/oeqa/utils/subprocesstweak.py diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py index a89bd117c0..1dad763ff1 100644 --- a/meta/lib/oeqa/oetest.py +++ b/meta/lib/oeqa/oetest.py @@ -135,15 +135,6 @@ class oeRuntimeTest(oeTest): if status != 0: return status -class OETestCalledProcessError(subprocess.CalledProcessError): - def __str__(self): - if hasattr(self, "stderr"): - return "Command '%s' returned non-zero exit status %d with output %s and stderr %s" % (self.cmd, self.returncode, self.output, self.stderr) - else: - return "Command '%s' returned non-zero exit status %d with output %s" % (self.cmd, self.returncode, self.output) - -subprocess.CalledProcessError = OETestCalledProcessError - def getmodule(pos=2): # stack returns a list of tuples containg frame information # First element of the list the is current frame, caller is 1 diff --git a/meta/lib/oeqa/utils/subprocesstweak.py b/meta/lib/oeqa/utils/subprocesstweak.py new file mode 100644 index 0000000000..1f7d11b55c --- /dev/null +++ b/meta/lib/oeqa/utils/subprocesstweak.py @@ -0,0 +1,19 @@ +import subprocess + +class OETestCalledProcessError(subprocess.CalledProcessError): + def __str__(self): + def strify(o): + if isinstance(o, bytes): + return o.decode("utf-8", errors="replace") + else: + return o + + s = "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode) + if hasattr(self, "output") and self.output: + s = s + "\nStandard Output: " + strify(self.output) + if hasattr(self, "stderr") and self.stderr: + s = s + "\nStandard Error: " + strify(self.stderr) + return s + +def errors_have_output(): + subprocess.CalledProcessError = OETestCalledProcessError -- cgit 1.2.3-korg