@@ -138,10 +138,10 @@ def create_step(self, name: str, description: str | None = None) -> TestStep:
138138
139139 return step
140140
141- def report_measurement (self , measurement : TestMeasurement , step : TestStep ):
141+ def report_outcome (self , outcome : bool , step : TestStep ):
142142 """Report a failure to the report context."""
143143 # Failures will be propogated when the step exits.
144- if not measurement . passed :
144+ if not outcome :
145145 self .open_step_results [step .step_path ] = False
146146 self .any_failures = True
147147
@@ -303,10 +303,24 @@ def measure(
303303 )
304304 evaluate_measurement_bounds (create , value , bounds )
305305 measurement = self .client .test_results .create_measurement (create )
306- self .report_context .report_measurement (measurement , self .current_step )
306+ self .report_context .report_outcome (measurement . passed , self .current_step )
307307
308308 return measurement .passed
309309
310+ def report_outcome (self , name : str , result : bool , reason : str | None = None ) -> bool :
311+ """Report an outcome from some action or measurement. Creates a substep that is pass/fail with the optional reason as the description.
312+
313+ Args:
314+ name: The name of the substep.
315+ result: True if the action or measurement passed, False otherwise.
316+ reason: [Optional] The context to include in the description of the substep.
317+
318+ returns: The given result so the function can be used in line.
319+ """
320+ with self .substep (name = name , description = reason ) as substep :
321+ self .report_context .report_outcome (result , substep .current_step )
322+ return result
323+
310324 def substep (self , name : str , description : str | None = None ) -> NewStep :
311325 """Alias to return a new step context manager from the current step. The ReportContext will manage nesting of steps."""
312326 return self .report_context .new_step (name = name , description = description )
0 commit comments