11import pytest
2+ import allure_commons
23
3- from allure .utils import now
4- from allure .utils import md5
5- from allure .utils import uuid4
6- from allure .logger import AllureLogger
7- from allure .model2 import TestStepResult , TestResult , TestBeforeResult , TestAfterResult
8- from allure .model2 import TestResultContainer
9- from allure .model2 import StatusDetails
10- from allure .model2 import Parameter
11- from allure .model2 import Label , Link
12- from allure .model2 import Status
4+ from allure_commons .utils import now
5+ from allure_commons .utils import md5
6+ from allure_commons .utils import uuid4
7+
8+ from allure_commons .logger import AllureLogger
9+
10+ from allure_commons .model2 import TestStepResult , TestResult , TestBeforeResult , TestAfterResult
11+ from allure_commons .model2 import TestResultContainer
12+ from allure_commons .model2 import StatusDetails
13+ from allure_commons .model2 import Parameter
14+ from allure_commons .model2 import Label , Link
15+ from allure_commons .model2 import Status
1316
1417from allure_pytest .utils import allure_parameters
1518from allure_pytest .utils import allure_labels , allure_links
@@ -23,14 +26,14 @@ def __init__(self, config):
2326 self .allure_logger = AllureLogger (config .option .allure_report_dir )
2427 self ._cache = ItemCache ()
2528
26- @pytest .hookimpl
27- def pytest_allure_before_step (self , uuid , title , params ):
29+ @allure_commons .hookimpl
30+ def start_step (self , uuid , title , params ):
2831 parameters = [Parameter (name = name , value = value ) for name , value in params ]
2932 step = TestStepResult (name = title , start = now (), parameters = parameters )
3033 self .allure_logger .start_step (None , uuid , step )
3134
32- @pytest .hookimpl
33- def pytest_allure_after_step (self , uuid , exc_type , exc_val , exc_tb ):
35+ @allure_commons .hookimpl
36+ def stop_step (self , uuid , exc_type , exc_val , exc_tb ):
3437 status = Status .PASSED
3538 if exc_type is not None :
3639 if exc_type == pytest .skip .Exception :
@@ -40,13 +43,13 @@ def pytest_allure_after_step(self, uuid, exc_type, exc_val, exc_tb):
4043
4144 self .allure_logger .stop_step (uuid , stop = now (), status = status )
4245
43- @pytest .hookimpl
44- def pytest_allure_before_finalizer (self , parent_uuid , uuid , name ):
46+ @allure_commons .hookimpl
47+ def start_fixture (self , parent_uuid , uuid , name ):
4548 after_fixture = TestAfterResult (name = name , start = now ())
4649 self .allure_logger .start_after_fixture (parent_uuid , uuid , after_fixture )
4750
48- @pytest .hookimpl
49- def pytest_allure_after_finalizer (self , uuid , exc_type , exc_val , exc_tb ):
51+ @allure_commons .hookimpl
52+ def stop_fixture (self , uuid , exc_type , exc_val , exc_tb ):
5053 self .allure_logger .stop_after_fixture (uuid , stop = now ())
5154
5255 @pytest .hookimpl (hookwrapper = True , tryfirst = True )
@@ -109,7 +112,8 @@ def pytest_fixture_setup(self, fixturedef, request):
109112 self .allure_logger .stop_before_fixture (before_fixture_uuid , stop = now ())
110113
111114 for index , finalizer in enumerate (fixturedef ._finalizer or ()):
112- fixturedef ._finalizer [index ] = FinalizerSpy (container_uuid , fixturedef .argname , finalizer , self .config )
115+ name = u'{fixture}::{finalizer}' .format (fixture = fixturedef .argname , finalizer = finalizer .__name__ )
116+ fixturedef ._finalizer [index ] = allure_commons .fixture (finalizer , parent_uuid = container_uuid , name = name )
113117
114118 @pytest .hookimpl (hookwrapper = True )
115119 def pytest_fixture_post_finalizer (self , fixturedef ):
@@ -158,39 +162,15 @@ def pytest_runtest_makereport(self, item, call):
158162 else :
159163 self .allure_logger .update_test (uuid , status = status )
160164
161- @pytest .hookimpl
162- def pytest_allure_attach_data (self , body , name , attachment_type , extension ):
165+ @allure_commons .hookimpl
166+ def attach_data (self , body , name , attachment_type , extension ):
163167 self .allure_logger .attach_data (uuid4 (), body , name = name , attachment_type = attachment_type , extension = extension )
164168
165- @pytest .hookimpl
166- def pytest_allure_attach_file (self , source , name , attachment_type , extension ):
169+ @allure_commons .hookimpl
170+ def attach_file (self , source , name , attachment_type , extension ):
167171 self .allure_logger .attach_file (uuid4 (), source , name = name , attachment_type = attachment_type , extension = extension )
168172
169173
170- class FinalizerSpy (object ):
171- def __init__ (self , parent_uuid , fixturename , finalizer , config ):
172- self ._parent_uuid = parent_uuid
173- self ._config = config
174- self ._finalizer = finalizer
175- self ._uuid = uuid4 ()
176- self ._name = "{fixture}::{finalizer}" .format (fixture = fixturename , finalizer = finalizer .__name__ )
177-
178- def __call__ (self , * args , ** kwards ):
179- with self :
180- return self ._finalizer (* args , ** kwards )
181-
182- def __enter__ (self ):
183- self ._config .hook .pytest_allure_before_finalizer (parent_uuid = self ._parent_uuid ,
184- uuid = self ._uuid ,
185- name = self ._name )
186-
187- def __exit__ (self , exc_type , exc_val , exc_tb ):
188- self ._config .hook .pytest_allure_after_finalizer (uuid = self ._uuid ,
189- exc_type = exc_type ,
190- exc_val = exc_val ,
191- exc_tb = exc_tb )
192-
193-
194174class ItemCache (object ):
195175
196176 def __init__ (self ):
0 commit comments