sift_client.util.test_results.context_manager
¶
| CLASS | DESCRIPTION |
|---|---|
NewStep |
Context manager to create a new step in a test report. See usage example in init.py. |
ReportContext |
Context manager for a new TestReport. See usage example in init.py. |
NewStep
¶
NewStep(
report_context: ReportContext,
name: str,
description: str | None = None,
)
Bases: AbstractContextManager
Context manager to create a new step in a test report. See usage example in init.py.
Initialize a new step context.
| PARAMETER | DESCRIPTION |
|---|---|
report_context
|
The report context to create the step in.
TYPE:
|
name
|
The name of the step.
TYPE:
|
description
|
The description of the step.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__enter__ |
Enter the context manager to create a new step. |
__exit__ |
|
measure |
Measure a value and return the result. |
substep |
Alias to return a new step context manager from the current step. The ReportContext will manage nesting of steps. |
update_step_from_result |
Update the step based on its substeps and if there was an exception while executing the step. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
client |
TYPE:
|
current_step |
TYPE:
|
report_context |
TYPE:
|
current_step
class-attribute
instance-attribute
¶
current_step: TestStep | None = create_step(
name, description
)
measure
¶
measure(
*,
name: str,
value: float | str | bool,
bounds: dict[str, float]
| NumericBounds
| str
| None = None,
timestamp: datetime | None = None,
unit: str | None = None,
) -> bool
Measure a value and return the result.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name of the measurement.
TYPE:
|
value
|
The value of the measurement.
TYPE:
|
bounds
|
[Optional] The bounds to compare the value to.
TYPE:
|
timestamp
|
[Optional] The timestamp of the measurement. Defaults to the current time.
TYPE:
|
unit
|
[Optional] The unit of the measurement.
TYPE:
|
returns: The result of the measurement.
substep
¶
substep(
name: str, description: str | None = None
) -> NewStep
Alias to return a new step context manager from the current step. The ReportContext will manage nesting of steps.
update_step_from_result
¶
update_step_from_result(
exc: type[Exception] | None,
exc_value: Exception | None,
tb: TracebackException | None,
)
Update the step based on its substeps and if there was an exception while executing the step.
| PARAMETER | DESCRIPTION |
|---|---|
exc
|
The class of Exception that was raised.
TYPE:
|
exc_value
|
The exception value.
TYPE:
|
tb
|
The traceback object.
TYPE:
|
ReportContext
¶
ReportContext(
client: SiftClient,
name: str,
test_system_name: str | None = None,
system_operator: str | None = None,
test_case: str | None = None,
)
Bases: AbstractContextManager
Context manager for a new TestReport. See usage example in init.py.
Initialize a new report context.
| PARAMETER | DESCRIPTION |
|---|---|
client
|
The Sift client to use to create the report.
TYPE:
|
name
|
The name of the report.
TYPE:
|
test_system_name
|
The name of the test system. Will default to the hostname if not provided.
TYPE:
|
system_operator
|
The operator of the test system. Will default to the current user if not provided.
TYPE:
|
test_case
|
The name of the test case. Will default to the basename of the file containing the test if not provided.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
__enter__ |
|
__exit__ |
|
create_step |
Create a new step in the report context. |
exit_step |
Exit a step and update the report context. |
get_next_step_path |
Get the next step path for the current depth. |
new_step |
Alias to return a new step context manager from this report context. Use create_step for actually creating a TestStep in the current context. |
report_measurement |
Report a failure to the report context. |
resolve_and_propagate_step_result |
Resolve the result of a step and propagate the result to the parent step if it failed. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
any_failures |
TYPE:
|
open_step_results |
TYPE:
|
report |
TYPE:
|
step_is_open |
TYPE:
|
step_number_at_depth |
TYPE:
|
step_stack |
TYPE:
|
create_step
¶
create_step(
name: str, description: str | None = None
) -> TestStep
Create a new step in the report context.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name of the step.
TYPE:
|
description
|
The description of the step.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TestStep
|
The created step. |
new_step
¶
new_step(
name: str, description: str | None = None
) -> NewStep
Alias to return a new step context manager from this report context. Use create_step for actually creating a TestStep in the current context.
report_measurement
¶
report_measurement(
measurement: TestMeasurement, step: TestStep
)
Report a failure to the report context.