46
46
_HAS_TEST_AVOIDED = (int (slash .__version__ .split ('.' )[0 ]) >= 1 )
47
47
_HAS_SESSION_INTERRUPT = hasattr (slash .hooks , 'session_interrupt' )
48
48
_HAS_TEST_DISTRIBUTED = hasattr (slash .hooks , 'test_distributed' )
49
+ _HAS_APP_QUIT = hasattr (slash .hooks , 'app_quit' )
49
50
50
51
def handle_exceptions (func ):
51
52
@@ -76,6 +77,7 @@ def __init__(self, url=None, keepalive_interval=None, runtoken=None,
76
77
self ._error_containers = {}
77
78
self ._runtoken = runtoken
78
79
self ._propagate_exceptions = propagate_exceptions
80
+ self ._started = False
79
81
80
82
@property
81
83
def rest_url (self ):
@@ -158,6 +160,7 @@ def _notify_session_start(self):
158
160
metadata = metadata ,
159
161
** self ._get_extra_session_start_kwargs ()
160
162
)
163
+ self ._started = True
161
164
for warning in slash .context .session .warnings :
162
165
self .warning_added (warning )
163
166
for label in self .current_config .session_labels :
@@ -277,6 +280,7 @@ def test_distributed(self, test_logical_id, worker_session_id): #pylint: disable
277
280
if 'report_test_distributed' in self .client .api .info ().endpoints :
278
281
self .current_test = self .session .report_test_distributed (test_logical_id )
279
282
283
+
280
284
@handle_exceptions
281
285
def test_skip (self , reason = None ):
282
286
self .current_test .mark_skipped (reason = reason )
@@ -409,6 +413,16 @@ def test_end(self):
409
413
410
414
@handle_exceptions
411
415
def session_end (self ):
416
+ self ._session_report_end ('session_end' )
417
+
418
+ @slash .plugins .register_if (_HAS_APP_QUIT )
419
+ @handle_exceptions # pylint: disable=unused-argument
420
+ def app_quit (self ):
421
+ self ._session_report_end ('app_quit' )
422
+
423
+ def _session_report_end (self , hook_name ):
424
+ if not self ._started :
425
+ return
412
426
try :
413
427
if self ._keepalive_thread is not None :
414
428
self ._keepalive_thread .stop ()
@@ -419,8 +433,9 @@ def session_end(self):
419
433
if self .client .api .info ().endpoints .report_session_end .version >= 2 :
420
434
kwargs ['has_fatal_errors' ] = has_fatal_errors
421
435
self .session .report_end (** kwargs )
436
+ self ._started = False
422
437
except Exception : # pylint: disable=broad-except
423
- _logger .error ('Exception ignored in session_end' , exc_info = True )
438
+ _logger .error ('Exception ignored in {}' . format ( hook_name ) , exc_info = True )
424
439
425
440
@handle_exceptions
426
441
def error_added (self , result , error ):
0 commit comments