From 33d90c7f2b5dc74382f033aa64b32c7a96e20102 Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Fri, 7 Aug 2020 16:21:14 +0200 Subject: [PATCH] Remove duplicate exception tracebacks from test reporting Change-Id: Idae9c7edf55a33f9d58dc72213aa88c52130c5c3 --- tobiko/common/_exception.py | 8 ++++---- tobiko/common/_retry.py | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tobiko/common/_exception.py b/tobiko/common/_exception.py index c4dbaf44f..717b11a83 100644 --- a/tobiko/common/_exception.py +++ b/tobiko/common/_exception.py @@ -92,12 +92,12 @@ class ExceptionInfo(collections.namedtuple('ExceptionInfo', def __enter__(self): return self + def __bool__(self): + return self.type is not None + def __exit__(self, _type, _value, _traceback): if self.reraise_on_exit: - if _type is not None: - LOG.exception("Exception occurred while handling %s(%s) " - "exception.", self.type, self.value) - self.reraise() + self.reraise() def reraise(self): if self.type is not None: diff --git a/tobiko/common/_retry.py b/tobiko/common/_retry.py index e04ef941a..525b6133a 100644 --- a/tobiko/common/_retry.py +++ b/tobiko/common/_retry.py @@ -80,9 +80,9 @@ class RetryAttempt(object): return max(0, self.count - self.number) def check_count_left(self) -> _time.Seconds: - with _exception.exc_info(): - if self.count_left == 0: - raise RetryCountLimitError(attempt=self) + if self.count_left == 0: + _exception.exc_info().reraise() + raise RetryCountLimitError(attempt=self) return self.count_left @property @@ -93,9 +93,9 @@ class RetryAttempt(object): return max(0., self.timeout - self.elapsed_time) def check_time_left(self) -> _time.Seconds: - with _exception.exc_info(): - if self.time_left == 0.: - raise RetryTimeLimitError(attempt=self) + if self.time_left == 0.: + _exception.exc_info().reraise() + raise RetryTimeLimitError(attempt=self) return self.time_left def check_limits(self):