1515from allure_commons .types import LabelType
1616from allure_pytest .utils import allure_labels , allure_links , pytest_markers
1717from allure_pytest .utils import allure_full_name , allure_package
18+ from allure_pytest .utils import get_status , get_status_details
19+ from allure_pytest .utils import get_outcome_status , get_outcome_status_details
1820
1921
2022class AllureListener (object ):
2123
22- def __init__ (self , config ):
23- self .config = config
24+ def __init__ (self ):
2425 self .allure_logger = AllureReporter ()
2526 self ._cache = ItemCache ()
2627
@@ -32,14 +33,10 @@ def start_step(self, uuid, title, params):
3233
3334 @allure_commons .hookimpl
3435 def stop_step (self , uuid , exc_type , exc_val , exc_tb ):
35- status = Status .PASSED
36- if exc_type is not None :
37- if exc_type == pytest .skip .Exception :
38- status = Status .SKIPPED
39- else :
40- status = Status .FAILED
41-
42- self .allure_logger .stop_step (uuid , stop = now (), status = status )
36+ self .allure_logger .stop_step (uuid ,
37+ stop = now (),
38+ status = get_status (exc_val ),
39+ statusDetails = get_status_details (exc_type , exc_val , exc_tb ))
4340
4441 @allure_commons .hookimpl
4542 def start_fixture (self , parent_uuid , uuid , name ):
@@ -48,7 +45,10 @@ def start_fixture(self, parent_uuid, uuid, name):
4845
4946 @allure_commons .hookimpl
5047 def stop_fixture (self , parent_uuid , uuid , name , exc_type , exc_val , exc_tb ):
51- self .allure_logger .stop_after_fixture (uuid , stop = now ())
48+ self .allure_logger .stop_after_fixture (uuid ,
49+ stop = now (),
50+ status = get_status (exc_val ),
51+ statusDetails = get_status_details (exc_type , exc_val , exc_tb ))
5252
5353 @pytest .hookimpl (hookwrapper = True , tryfirst = True )
5454 def pytest_runtest_protocol (self , item , nextitem ):
@@ -69,6 +69,9 @@ def pytest_runtest_protocol(self, item, nextitem):
6969
7070 yield
7171
72+ for name , value in item .callspec .params .items () if hasattr (item , 'callspec' ) else ():
73+ self .allure_logger .update_test (uuid , parameters = Parameter (name , represent (value )))
74+
7275 test_case .labels .extend ([Label (name = name , value = value ) for name , value in allure_labels (item )])
7376 test_case .labels .extend ([Label (name = LabelType .TAG , value = value ) for value in pytest_markers (item )])
7477 test_case .labels .append (Label (name = LabelType .FRAMEWORK , value = 'pytest' ))
@@ -86,11 +89,10 @@ def pytest_runtest_protocol(self, item, nextitem):
8689 @pytest .hookimpl (hookwrapper = True )
8790 def pytest_runtest_call (self , item ):
8891 uuid = self ._cache .get (item .nodeid )
89- for name , value in item .callspec .params .items () if hasattr (item , 'callspec' ) else ():
90- self .allure_logger .update_test (uuid , parameters = Parameter (name , represent (value )))
91-
9292 self .allure_logger .update_test (uuid , start = now ())
93+
9394 yield
95+
9496 self .allure_logger .update_test (uuid , stop = now ())
9597
9698 @pytest .hookimpl (hookwrapper = True )
@@ -110,12 +112,15 @@ def pytest_fixture_setup(self, fixturedef, request):
110112 before_fixture = TestBeforeResult (name = fixture_name , start = now ())
111113 self .allure_logger .start_before_fixture (container_uuid , before_fixture_uuid , before_fixture )
112114
113- yield
115+ outcome = yield
114116
115- self .allure_logger .stop_before_fixture (before_fixture_uuid , stop = now ())
117+ self .allure_logger .stop_before_fixture (before_fixture_uuid ,
118+ stop = now (),
119+ status = get_outcome_status (outcome ),
120+ statusDetails = get_outcome_status_details (outcome ))
116121
117122 for index , finalizer in enumerate (fixturedef ._finalizer or ()):
118- name = u '{fixture}::{finalizer}' .format (fixture = fixturedef .argname , finalizer = finalizer .__name__ )
123+ name = '{fixture}::{finalizer}' .format (fixture = fixturedef .argname , finalizer = finalizer .__name__ )
119124 fixturedef ._finalizer [index ] = allure_commons .fixture (finalizer , parent_uuid = container_uuid , name = name )
120125
121126 @pytest .hookimpl (hookwrapper = True )
0 commit comments