From a86abd37e96d56e9be8d551042b449a8ba058da8 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Dec 11 2018 12:46:52 +0000 Subject: Log stderr in run_command pytest_multihost's run_command() does not log stderr when a command fails. Wrap the function call to log stderr so it's easier to debug failing tests. Signed-off-by: Christian Heimes Reviewed-By: Alexander Bokovoy --- diff --git a/ipatests/pytest_ipa/integration/host.py b/ipatests/pytest_ipa/integration/host.py index 28f6e2c..6aed58a 100644 --- a/ipatests/pytest_ipa/integration/host.py +++ b/ipatests/pytest_ipa/integration/host.py @@ -18,6 +18,7 @@ # along with this program. If not, see . """Host class for integration testing""" +import subprocess import pytest_multihost.host @@ -60,6 +61,24 @@ class Host(pytest_multihost.host.Host): from ipatests.pytest_ipa.integration.env_config import host_to_env return host_to_env(self, **kwargs) + def run_command(self, argv, set_env=True, stdin_text=None, + log_stdout=True, raiseonerr=True, + cwd=None, bg=False, encoding='utf-8'): + # Wrap run_command to log stderr on raiseonerr=True + result = super().run_command( + argv, set_env=set_env, stdin_text=stdin_text, + log_stdout=log_stdout, raiseonerr=False, cwd=cwd, bg=bg, + encoding=encoding + ) + if result.returncode and raiseonerr: + result.log.error('stderr: %s', result.stderr_text) + raise subprocess.CalledProcessError( + result.returncode, argv, + result.stdout_text, result.stderr_text + ) + else: + return result + class WinHost(pytest_multihost.host.WinHost): """