From patchwork Wed Mar 1 16:02:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Purdie X-Patchwork-Id: 94716 Delivered-To: patch@linaro.org Received: by 10.140.20.113 with SMTP id 104csp1865777qgi; Wed, 1 Mar 2017 08:04:07 -0800 (PST) X-Received: by 10.98.141.138 with SMTP id p10mr9621264pfk.111.1488384246961; Wed, 01 Mar 2017 08:04:06 -0800 (PST) Return-Path: Received: from mail.openembedded.org (mail.openembedded.org. [140.211.169.62]) by mx.google.com with ESMTP id d194si4967299pfd.78.2017.03.01.08.04.06; Wed, 01 Mar 2017 08:04:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) client-ip=140.211.169.62; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) smtp.mailfrom=openembedded-core-bounces@lists.openembedded.org Received: from review.yoctoproject.org (localhost [127.0.0.1]) by mail.openembedded.org (Postfix) with ESMTP id 4AFB87759B; Wed, 1 Mar 2017 16:03:06 +0000 (UTC) X-Original-To: openembedded-core@lists.openembedded.org Delivered-To: openembedded-core@lists.openembedded.org Received: from dan.rpsys.net (5751f4a1.skybroadband.com [87.81.244.161]) by mail.openembedded.org (Postfix) with ESMTP id 7212477576 for ; Wed, 1 Mar 2017 16:02:59 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by dan.rpsys.net (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id v21G2pSA011995; Wed, 1 Mar 2017 16:02:52 GMT Received: from dan.rpsys.net ([127.0.0.1]) by localhost (dan.rpsys.net [127.0.0.1]) (amavisd-new, port 10024) with LMTP id C1fUm_0dxwqA; Wed, 1 Mar 2017 16:02:52 +0000 (GMT) Received: from hex ([192.168.3.34]) (authenticated bits=0) by dan.rpsys.net (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id v21G2kax011981 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 1 Mar 2017 16:02:47 GMT Received: from richard by hex with local (Exim 4.86_2) (envelope-from ) id 1cj6iE-0004oK-Qg; Wed, 01 Mar 2017 16:02:46 +0000 From: Richard Purdie To: openembedded-core@lists.openembedded.org Date: Wed, 1 Mar 2017 16:02:40 +0000 Message-Id: <1488384162-18397-10-git-send-email-richard.purdie@linuxfoundation.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488384162-18397-1-git-send-email-richard.purdie@linuxfoundation.org> References: <1488384162-18397-1-git-send-email-richard.purdie@linuxfoundation.org> Subject: [OE-core] [PATCH 10/12] oeqa: add output to subprocess exceptions X-BeenThere: openembedded-core@lists.openembedded.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Patches and discussions about the oe-core layer List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: openembedded-core-bounces@lists.openembedded.org Errors-To: openembedded-core-bounces@lists.openembedded.org From: Ross Burton 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. 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 -- 2.7.4 -- _______________________________________________ Openembedded-core mailing list Openembedded-core@lists.openembedded.org http://lists.openembedded.org/mailman/listinfo/openembedded-core diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py index a89bd11..1dad763 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 0000000..1f7d11b --- /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