Skip to content

Commit 3d4b153

Browse files
committed
Support reporting interruption exceptions (fix #59)
1 parent 8301bda commit 3d4b153

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

backslash/contrib/slash_plugin.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ def test_avoided(self, reason):
194194
self.test_skip(reason=reason)
195195
self.test_end()
196196

197+
197198
@handle_exceptions
198199
def test_interrupt(self):
199200
if self.current_test is not None:
@@ -406,6 +407,20 @@ def session_end(self):
406407

407408
@handle_exceptions
408409
def error_added(self, result, error):
410+
self._add_exception(result=result, exception=error)
411+
412+
@slash.plugins.register_if(hasattr(slash.hooks, 'interruption_added'))
413+
@handle_exceptions
414+
def interruption_added(self, result, exception):
415+
self._add_exception(result=result, exception=exception, is_interruption=True)
416+
417+
418+
def _add_exception(self, result, exception, is_interruption=False):
419+
has_interruptions = self.client.api.info().endpoints.add_error.version >= 4
420+
if is_interruption and not has_interruptions:
421+
_logger.debug('Server does not support recording is_interruption exceptions. Skipping reporting')
422+
return
423+
409424
if result is slash.session.results.global_result:
410425
error_container = self.session
411426
else:
@@ -415,16 +430,21 @@ def error_added(self, result, error):
415430
_logger.debug('Could not determine error container to report on for {}', result)
416431
return
417432

418-
kwargs = {'exception_type': error.exception_type.__name__ if error.exception_type is not None else None,
419-
'traceback': distill_slash_traceback(error), 'exception_attrs': getattr(error, 'exception_attributes', NOTHING)}
420-
if error.message:
421-
message = error.message
422-
elif hasattr(error, 'exception_str'):
423-
message = error.exception_str
433+
kwargs = {'exception_type': exception.exception_type.__name__ if exception.exception_type is not None else None,
434+
'traceback': distill_slash_traceback(exception), 'exception_attrs': getattr(exception, 'exception_attributes', NOTHING)}
435+
if exception.message:
436+
message = exception.message
437+
elif hasattr(exception, 'exception_str'):
438+
message = exception.exception_str
424439
else:
425-
message = str(error.exception)
440+
message = str(exception.exception)
441+
442+
426443
kwargs['message'] = message
427444

445+
if has_interruptions:
446+
kwargs['is_interruption'] = is_interruption
447+
428448
for compact_variables in [False, True]:
429449
if compact_variables:
430450
for frame in kwargs['traceback']:

backslash/error_container.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313

1414
class ErrorContainer(object):
1515

16-
def add_error(self, message, exception_type=NOTHING, traceback=NOTHING, timestamp=NOTHING, is_failure=NOTHING, exception_attrs=NOTHING):
16+
def add_error(self, message, exception_type=NOTHING, traceback=NOTHING,
17+
timestamp=NOTHING, is_failure=NOTHING, exception_attrs=NOTHING, is_interruption=NOTHING):
1718

1819
kwargs = {self._get_id_key(): self.id, # pylint: disable=no-member
1920
'message': message,
2021
'exception_type': exception_type,
2122
'is_failure': is_failure,
22-
'timestamp': timestamp
23+
'timestamp': timestamp,
24+
'is_interruption': is_interruption,
2325
}
2426

2527
add_error_version = self.client.api.info().endpoints.add_error.version # pylint: disable=no-member

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Changelog
22
=========
33

44
* :feature:`60` Clean up UI URL generation, added ``Backslash.get_ui_url`` helper method
5+
* :feature:`59` Support reporting interruption exceptions to Backslash
56
* :feature:`58` Support reporting timing metrics
67
* :feature:`57` Support reporting test status description
78
* :release:`2.31.2 <14-9-2017>`

0 commit comments

Comments
 (0)