11
11
import pytest
12
12
import sys
13
13
import time
14
+ import traceback
14
15
import unittest
15
16
import uuid
16
17
from pyvirtualdisplay import Display
@@ -414,17 +415,23 @@ def setUp(self):
414
415
self .testcase_manager .insert_testcase_data (data_payload )
415
416
self .case_start_time = int (time .time () * 1000 )
416
417
417
- def __insert_test_result (self , state , err = None ):
418
+ def __insert_test_result (self , state , err ):
418
419
data_payload = TestcaseDataPayload ()
419
420
data_payload .runtime = int (time .time () * 1000 ) - self .case_start_time
420
421
data_payload .guid = self .testcase_guid
421
422
data_payload .execution_guid = self .execution_guid
422
423
data_payload .state = state
423
- if err is not None :
424
- data_payload .message = err [1 ].__str__ ().split (
425
- '''-------------------- >> '''
426
- '''begin captured logging'''
427
- ''' << --------------------''' , 1 )[0 ]
424
+ if err :
425
+ tb_string = traceback .format_exc ()
426
+ if "Message: " in tb_string :
427
+ data_payload .message = "Message: " + tb_string .split (
428
+ "Message: " )[- 1 ]
429
+ elif "Exception: " in tb_string :
430
+ data_payload .message = tb_string .split ("Exception: " )[- 1 ]
431
+ elif "Error: " in tb_string :
432
+ data_payload .message = tb_string .split ("Error: " )[- 1 ]
433
+ else :
434
+ data_payload .message = "Unknown Error: See Stacktrace"
428
435
self .testcase_manager .update_testcase_data (data_payload )
429
436
430
437
def tearDown (self ):
@@ -469,9 +476,9 @@ def tearDown(self):
469
476
self .display .stop ()
470
477
if self .with_db_reporting :
471
478
if sys .exc_info ()[1 ] is not None :
472
- self .__insert_test_result (constants .State .ERROR )
479
+ self .__insert_test_result (constants .State .ERROR , True )
473
480
else :
474
- self .__insert_test_result (constants .State .PASS )
481
+ self .__insert_test_result (constants .State .PASS , False )
475
482
runtime = int (time .time () * 1000 ) - self .execution_start_time
476
483
self .testcase_manager .update_execution_data (
477
484
self .execution_guid , runtime )
@@ -496,6 +503,6 @@ def tearDown(self):
496
503
if self .with_db_reporting :
497
504
self .testcase_manager = TestcaseManager (self .database_env )
498
505
data_payload = TestcaseDataPayload ()
499
- data_payload .guid = guid
506
+ data_payload .guid = self . testcase_guid
500
507
data_payload .logURL = index_file
501
508
self .testcase_manager .update_testcase_log_url (data_payload )
0 commit comments