@@ -1126,13 +1126,23 @@ def _get_exception_message(self):
1126
1126
""" This method extracts the message from an exception if there
1127
1127
was an exception that occurred during the test, assuming
1128
1128
that the exception was in a try/except block and not thrown. """
1129
- exception_info = sys .exc_info ()[1 ]
1130
- if hasattr (exception_info , 'msg' ):
1131
- exc_message = exception_info .msg
1132
- elif hasattr (exception_info , 'message' ):
1133
- exc_message = exception_info .message
1129
+ if sys .version .startswith ('3' ) and hasattr (self , '_outcome' ):
1130
+ exception_info = self ._outcome .errors
1131
+ if exception_info :
1132
+ try :
1133
+ exc_message = exception_info [0 ][1 ][1 ]
1134
+ except :
1135
+ exc_message = "(Unknown Exception)"
1136
+ else :
1137
+ exc_message = "(Unknown Exception)"
1134
1138
else :
1135
- exc_message = '(Unknown Exception)'
1139
+ exception_info = sys .exc_info ()[1 ]
1140
+ if hasattr (exception_info , 'msg' ):
1141
+ exc_message = exception_info .msg
1142
+ elif hasattr (exception_info , 'message' ):
1143
+ exc_message = exception_info .message
1144
+ else :
1145
+ exc_message = '(Unknown Exception)'
1136
1146
return exc_message
1137
1147
1138
1148
def _package_check (self ):
@@ -1405,12 +1415,18 @@ def tearDown(self):
1405
1415
You'll need to add the following line to the subclass's tearDown():
1406
1416
super(SubClassOfBaseCase, self).tearDown()
1407
1417
"""
1418
+ has_exception = False
1419
+ if sys .version .startswith ('3' ) and hasattr (self , '_outcome' ):
1420
+ if self ._outcome .errors :
1421
+ has_exception = True
1422
+ else :
1423
+ has_exception = sys .exc_info ()[1 ] is not None
1408
1424
if self .page_check_failures :
1409
1425
print (
1410
1426
"\n When using self.check_assert_***() methods in your tests, "
1411
1427
"remember to call self.process_checks() afterwards. "
1412
1428
"Now calling in tearDown()...\n Failures Detected:" )
1413
- if not sys . exc_info ()[ 1 ] :
1429
+ if not has_exception :
1414
1430
self .process_checks ()
1415
1431
else :
1416
1432
self .process_checks (print_only = True )
@@ -1428,10 +1444,9 @@ def tearDown(self):
1428
1444
self ._testMethodName )
1429
1445
if self .with_selenium :
1430
1446
# Save a screenshot if logging is on when an exception occurs
1431
- is_exception = sys .exc_info ()[1 ] is not None
1432
- if is_exception :
1447
+ if has_exception :
1433
1448
self ._add_pytest_html_extra ()
1434
- if self .with_testing_base and is_exception :
1449
+ if self .with_testing_base and has_exception :
1435
1450
test_logpath = self .log_path + "/" + test_id
1436
1451
if not os .path .exists (test_logpath ):
1437
1452
os .makedirs (test_logpath )
@@ -1441,15 +1456,15 @@ def tearDown(self):
1441
1456
# Log everything if nothing specified (if testing_base)
1442
1457
log_helper .log_screenshot (test_logpath , self .driver )
1443
1458
log_helper .log_test_failure_data (
1444
- test_logpath , self .driver , self .browser )
1459
+ self , test_logpath , self .driver , self .browser )
1445
1460
log_helper .log_page_source (test_logpath , self .driver )
1446
1461
else :
1447
1462
if self .with_screen_shots :
1448
1463
log_helper .log_screenshot (
1449
1464
test_logpath , self .driver )
1450
1465
if self .with_basic_test_info :
1451
1466
log_helper .log_test_failure_data (
1452
- test_logpath , self .driver , self .browser )
1467
+ self , test_logpath , self .driver , self .browser )
1453
1468
if self .with_page_source :
1454
1469
log_helper .log_page_source (
1455
1470
test_logpath , self .driver )
@@ -1466,14 +1481,14 @@ def tearDown(self):
1466
1481
self .display .stop ()
1467
1482
self .display = None
1468
1483
if self .with_db_reporting :
1469
- if sys . exc_info ()[ 1 ] is not None :
1484
+ if has_exception :
1470
1485
self .__insert_test_result (constants .State .ERROR , True )
1471
1486
else :
1472
1487
self .__insert_test_result (constants .State .PASS , False )
1473
1488
runtime = int (time .time () * 1000 ) - self .execution_start_time
1474
1489
self .testcase_manager .update_execution_data (
1475
1490
self .execution_guid , runtime )
1476
- if self .with_s3_logging and ( sys . exc_info ()[ 1 ] is not None ) :
1491
+ if self .with_s3_logging and has_exception :
1477
1492
""" After each testcase, upload logs to the S3 bucket. """
1478
1493
s3_bucket = S3LoggingBucket ()
1479
1494
guid = str (uuid .uuid4 ().hex )
0 commit comments