[elbe-devel] [PATCH 02/10] test: add special handling for ElbeTestException

Bastian Germann bage at linutronix.de
Thu Apr 1 18:12:40 CEST 2021


Am 01.04.21 um 13:15 schrieb Torben Hohn:
> ElbeTestException saves the output of the failing command.
> This output generally contains newlines which are not handled
> properly when they end up in an xml attribute.
> 
> The output failure_output node is declared as the stacktrace in jenkins.
> 
> Put the backtrace there, and use the stdout attribute for the output.
> 
> Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>

Reviewed-by: Bastian Germann <bage at linutronix.de>

> ---
>   elbepack/commands/test.py | 29 +++++++++++++++++++++++++----
>   1 file changed, 25 insertions(+), 4 deletions(-)
> 
> diff --git a/elbepack/commands/test.py b/elbepack/commands/test.py
> index c67f7c04a..8f19733ae 100644
> --- a/elbepack/commands/test.py
> +++ b/elbepack/commands/test.py
> @@ -138,14 +138,29 @@ class ElbeTestResult(unittest.TestResult):
>           """Called when an error has occurred. 'err' is a tuple of values as
>              returned by sys.exc_info().
>           """
> -        self.current_case.add_error_info(self._exc_info_to_string(err, test))
> +
> +        message = str(err[1])
> +        output = self._exc_info_to_string(err, test)
> +
> +        if err is not None:
> +            if issubclass(err[0], ElbeTestException):
> +                self.current_case.stdout = err[1].out
> +
> +        self.current_case.add_error_info(message, output)
>           super().addError(test, err)
>   
>       def addFailure(self, test, err):
>           """Called when an error has occurred. 'err' is a tuple of values as
>              returned by sys.exc_info()."""
>   
> -        self.current_case.add_failure_info(self._exc_info_to_string(err, test))
> +        message = str(err[1])
> +        output = self._exc_info_to_string(err, test)
> +
> +        if err is not None:
> +            if issubclass(err[0], ElbeTestException):
> +                self.current_case.stdout = err[1].out
> +
> +        self.current_case.add_failure_info(message, output)
>           super().addFailure(test, err)
>   
>       def addSubTest(self, test, subtest, err):
> @@ -157,11 +172,17 @@ class ElbeTestResult(unittest.TestResult):
>           self.current_case = junit.TestCase(name=str(subtest))
>           self.cases.append(self.current_case)
>   
> +        message = str(err[1])
> +        output = self._exc_info_to_string(err, test)
> +
>           if err is not None:
> +            if issubclass(err[0], ElbeTestException):
> +                self.current_case.stdout = err[1].out
> +
>               if issubclass(err[0], test.failureException):
> -                self.current_case.add_failure_info(message=self._exc_info_to_string(err, test))
> +                self.current_case.add_failure_info(message, output)
>               else:
> -                self.current_case.add_error_info(message=self._exc_info_to_string(err, test))
> +                self.current_case.add_error_info(message, output)
>   
>           super().addSubTest(test, subtest, err)
>   
> 


More information about the elbe-devel mailing list