Skip to content

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: ReportContext

name

The name of the step.

TYPE: str

description

The description of the step.

TYPE: str | None DEFAULT: None

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: SiftClient

current_step

TYPE: TestStep | None

report_context

TYPE: ReportContext

client instance-attribute

client: SiftClient = client

current_step class-attribute instance-attribute

current_step: TestStep | None = create_step(
    name, description
)

report_context instance-attribute

report_context: ReportContext = report_context

__enter__

__enter__()

Enter the context manager to create a new step.

returns: The current step.

__exit__

__exit__(exc, exc_value, tb)

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: str

value

The value of the measurement.

TYPE: float | str | bool

bounds

[Optional] The bounds to compare the value to.

TYPE: dict[str, float] | NumericBounds | str | None DEFAULT: None

timestamp

[Optional] The timestamp of the measurement. Defaults to the current time.

TYPE: datetime | None DEFAULT: None

unit

[Optional] The unit of the measurement.

TYPE: str | None DEFAULT: None

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: type[Exception] | None

exc_value

The exception value.

TYPE: Exception | None

tb

The traceback object.

TYPE: TracebackException | None

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: SiftClient

name

The name of the report.

TYPE: str

test_system_name

The name of the test system. Will default to the hostname if not provided.

TYPE: str | None DEFAULT: None

system_operator

The operator of the test system. Will default to the current user if not provided.

TYPE: str | None DEFAULT: None

test_case

The name of the test case. Will default to the basename of the file containing the test if not provided.

TYPE: str | None DEFAULT: None

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: bool

open_step_results

TYPE: dict[str, bool]

report

TYPE: TestReport

step_is_open

TYPE: bool

step_number_at_depth

TYPE: dict[int, int]

step_stack

TYPE: list[TestStep]

any_failures instance-attribute

any_failures: bool = False

open_step_results instance-attribute

open_step_results: dict[str, bool] = {}

report instance-attribute

report: TestReport = create(create)

step_is_open instance-attribute

step_is_open: bool = False

step_number_at_depth instance-attribute

step_number_at_depth: dict[int, int] = {}

step_stack instance-attribute

step_stack: list[TestStep] = []

__enter__

__enter__()

__exit__

__exit__(exc_type, exc_value, traceback)

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: str

description

The description of the step.

TYPE: str | None DEFAULT: None

RETURNS DESCRIPTION
TestStep

The created step.

exit_step

exit_step(step: TestStep)

Exit a step and update the report context.

get_next_step_path

get_next_step_path() -> str

Get the next step path for the current depth.

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.

resolve_and_propagate_step_result

resolve_and_propagate_step_result(
    step: TestStep, error_info: ErrorInfo | None = None
) -> bool

Resolve the result of a step and propagate the result to the parent step if it failed.