@@ -211,14 +211,19 @@ def __exit__(self, exc_type, exc_value, traceback):
211211 return True
212212
213213 def new_step (
214- self , name : str , description : str | None = None , assertion_as_fail_not_error : bool = True
214+ self ,
215+ name : str ,
216+ description : str | None = None ,
217+ assertion_as_fail_not_error : bool = True ,
218+ metadata : dict [str , str | float | bool ] | None = None ,
215219 ) -> NewStep :
216220 """Alias to return a new step context manager from this report context. Use create_step for actually creating a TestStep in the current context."""
217221 return NewStep (
218222 self ,
219223 name = name ,
220224 description = description ,
221225 assertion_as_fail_not_error = assertion_as_fail_not_error ,
226+ metadata = metadata ,
222227 )
223228
224229 def get_next_step_path (self ) -> str :
@@ -229,12 +234,20 @@ def get_next_step_path(self) -> str:
229234 prefix = f"{ step_path } ." if step_path else ""
230235 return f"{ prefix } { next_step_number } "
231236
232- def create_step (self , name : str , description : str | None = None ) -> TestStep :
237+ def create_step (
238+ self ,
239+ name : str ,
240+ description : str | None = None ,
241+ metadata : dict [str , str | float | bool ] | None = None ,
242+ ) -> TestStep :
233243 """Create a new step in the report context.
234244
235245 Args:
236246 name: The name of the step.
237247 description: The description of the step.
248+ metadata: [Optional] Structured key/value metadata to attach to the step. For
249+ metadata shared across every step in a report, prefer the `metadata` attribute
250+ of the enclosing `TestReport`.
238251
239252 Returns:
240253 The created step.
@@ -253,6 +266,7 @@ def create_step(self, name: str, description: str | None = None) -> TestStep:
253266 end_time = datetime .now (timezone .utc ),
254267 description = description ,
255268 parent_step_id = parent_step .id_ if parent_step else None ,
269+ metadata = metadata ,
256270 ),
257271 log_file = self .log_file ,
258272 )
@@ -324,6 +338,7 @@ def __init__(
324338 name : str ,
325339 description : str | None = None ,
326340 assertion_as_fail_not_error : bool = True ,
341+ metadata : dict [str , str | float | bool ] | None = None ,
327342 ):
328343 """Initialize a new step context.
329344
@@ -332,10 +347,11 @@ def __init__(
332347 name: The name of the step.
333348 description: The description of the step.
334349 assertion_as_fail_not_error: Mark steps with assertion errors as failed instead of error+traceback (some users want assertions to work as simple failures especially when using pytest).
350+ metadata: [Optional] Structured key/value metadata to attach to the step.
335351 """
336352 self .report_context = report_context
337353 self .client = report_context .client
338- self .current_step = self .report_context .create_step (name , description )
354+ self .current_step = self .report_context .create_step (name , description , metadata = metadata )
339355 self .assertion_as_fail_not_error = assertion_as_fail_not_error
340356
341357 def __enter__ (self ):
@@ -602,10 +618,16 @@ def report_outcome(self, name: str, result: bool, reason: str | None = None) ->
602618 self .report_context .record_step_outcome (result , substep .current_step )
603619 return result
604620
605- def substep (self , name : str , description : str | None = None ) -> NewStep :
621+ def substep (
622+ self ,
623+ name : str ,
624+ description : str | None = None ,
625+ metadata : dict [str , str | float | bool ] | None = None ,
626+ ) -> NewStep :
606627 """Alias to return a new step context manager from the current step. The ReportContext will manage nesting of steps."""
607628 return self .report_context .new_step (
608629 name = name ,
609630 description = description ,
610631 assertion_as_fail_not_error = self .assertion_as_fail_not_error ,
632+ metadata = metadata ,
611633 )
0 commit comments