@@ -42,6 +42,7 @@ def pytest_terminal_summary(terminalreporter, exitstatus, config):
42
42
"%40test.service%3A{}%20%40ci.pipeline.id%3A{}&index=citest" .format (dd_service , ci_pipeline_id )
43
43
)
44
44
45
+
45
46
except ImportError :
46
47
if os .getenv ("CI" , "false" ) == "true" and RECORD == "none" :
47
48
raise
@@ -104,24 +105,6 @@ def escape_reserved_keyword(word):
104
105
return word
105
106
106
107
107
- def pytest_bdd_before_scenario (request , feature , scenario ):
108
- if tracer is not None :
109
- span = tracer .current_span ()
110
- if span is not None :
111
- span .set_tag ("test.name" , scenario .name )
112
- span .set_tag ("test.suite" , scenario .feature .filename .split ("tests" )[- 1 ])
113
-
114
- codeowners = [f"@{ tag [5 :]} " for tag in scenario .tags | scenario .feature .tags if tag .startswith ("team:" )]
115
- if codeowners :
116
- try :
117
- default_value = span .get_tag ("test.codeowners" )
118
- default_codeowners = json .loads (default_value )
119
- codeowners .extend (default_codeowners )
120
- except Exception :
121
- pass
122
- span .set_tag ("test.codeowners" , json .dumps (codeowners ))
123
-
124
-
125
108
def pytest_bdd_after_scenario (request , feature , scenario ):
126
109
try :
127
110
ctx = request .getfixturevalue ("context" )
@@ -131,33 +114,6 @@ def pytest_bdd_after_scenario(request, feature, scenario):
131
114
undo ()
132
115
133
116
134
- def pytest_bdd_before_step (request , feature , scenario , step , step_func ):
135
- if tracer is None :
136
- return
137
-
138
- span = tracer .start_span (
139
- step .type ,
140
- resource = step .name ,
141
- span_type = step .type ,
142
- child_of = tracer .current_span (),
143
- activate = True ,
144
- )
145
- setattr (step_func , "__dd_span__" , span )
146
-
147
-
148
- def pytest_bdd_after_step (request , feature , scenario , step , step_func , step_func_args ):
149
- span = getattr (step_func , "__dd_span__" , None )
150
- if span is not None :
151
- span .finish ()
152
-
153
-
154
- def pytest_bdd_step_error (request , feature , scenario , step , step_func , step_func_args , exception ):
155
- span = getattr (step_func , "__dd_span__" , None )
156
- if span is not None :
157
- span .set_exc_info (type (exception ), exception , exception .__traceback__ )
158
- span .finish ()
159
-
160
-
161
117
def pytest_bdd_apply_tag (tag , function ):
162
118
"""Register tags as custom markers and skip test for '@skip' ones."""
163
119
skip_tags = {"skip" , "skip-python" }
@@ -283,8 +239,22 @@ def disable_recording(request):
283
239
@pytest .fixture
284
240
def vcr_config ():
285
241
config = dict (
286
- filter_headers = ("DD-API-KEY" , "DD-APPLICATION-KEY" , "User-Agent" , "Accept-Encoding" ),
287
- match_on = ["method" , "scheme" , "host" , "port" , "path" , "query" , "body" , "headers" ],
242
+ filter_headers = (
243
+ "DD-API-KEY" ,
244
+ "DD-APPLICATION-KEY" ,
245
+ "User-Agent" ,
246
+ "Accept-Encoding" ,
247
+ ),
248
+ match_on = [
249
+ "method" ,
250
+ "scheme" ,
251
+ "host" ,
252
+ "port" ,
253
+ "path" ,
254
+ "query" ,
255
+ "body" ,
256
+ "headers" ,
257
+ ],
288
258
)
289
259
if tracer :
290
260
from urllib .parse import urlparse
@@ -501,7 +471,13 @@ def build_param(p):
501
471
result = operation_method (** kwargs )
502
472
503
473
# register undo method
504
- context ["undo_operations" ].append (lambda : undo (api , version , operation_name , result , client = client ))
474
+ def undo_operation ():
475
+ return undo (api , version , operation_name , result , client = client )
476
+
477
+ if tracer :
478
+ undo_operation = tracer .wrap (name = "undo" , resource = operation ["step" ])(undo_operation )
479
+
480
+ context ["undo_operations" ].append (undo_operation )
505
481
506
482
# optional re-shaping
507
483
if "source" in operation :
@@ -580,7 +556,13 @@ def execute_request(undo, context, client, api_version):
580
556
operation_id = api_request ["request" ].__name__
581
557
response = api_request ["response" ][0 ]
582
558
583
- context ["undo_operations" ].append (lambda : undo (api , api_version , operation_id , response ))
559
+ def undo_operation ():
560
+ return undo (api , api_version , operation_id , response )
561
+
562
+ if tracer :
563
+ undo_operation = tracer .wrap (name = "undo" , resource = "execute request" )(undo_operation )
564
+
565
+ context ["undo_operations" ].append (undo_operation )
584
566
585
567
586
568
@when ("the request with pagination is sent" )
0 commit comments