scenario.scenariostack module

Scenario execution stack.

SCENARIO_STACK

Main instance of ScenarioStack.

class BuildingContext

Bases: object

Storage of instances under construction.

__init__()

Declares references of objects under construction.

Objects under construction:

  • scenario definition,

  • but no step definition!

    Warning

    We do not store a step definition reference here, fed from StepDefinition.__init__() especially, for the reason that we cannot guarantee that the reference of a volatile step definition would not take the place of a real step definition being built.

    See step_definition and fromoriginator() for further details on the step definition reference management.

__scenario_definitions

Scenario definitions being built.

pushscenariodefinition(scenario_definition)

Pushes the reference of the scenario definition being built to the building context of the scenario stack.

Parameters:

scenario_definition – Scenario definition being built.

popscenariodefinition(scenario_definition)

Pops the reference of the scenario definition being built from the building context of the scenario stack.

Parameters:

scenario_definition – Scenario definition being built.

property scenario_definition

Main scenario definition being built (i.e. the first), if any.

property step_definition

Step definition being built, if any.

The step definition being built is the one currently executed in scenariorunner.ScenarioRunner.ExecutionMode.BUILD_OBJECTS execution mode by ScenarioRunner._buildscenario().

Warning

This does not cover the case of method calls directly made in a step object initializer, and especially for:

In order to cover such cases, theses methods shall set an originator parameter when calling ScenarioRunner methods, to let the latter identify the appropriate instance being built with the help of the fromoriginator() method.

fromoriginator(originator)

Determines the actual object being built.

Parameters:

originatorStepUserApi instance that made a call.

Returns:

StepUserApi actually being built.

Fixes the originator reference from the current scenario definition being built to the current step definition being built if any.

Lets the originator reference as is otherwise:

class ScenarioStack

Bases: Logger

Scenario execution stack management.

This class acts as a helper for the ScenarioRunner class.

It also determines the scenario stack logging indentation.

Note

The fact that the ScenarioStack class is a helper for the ScenarioRunner one explains the definition of the additional methods and properties:

  • checkcurrentscenario(),

  • current_step,

  • current_action_result.

By the way, this makes this class being a bit more than just a scenario stack manager, but rather a scenario execution context manager.

Whatever, the name of this class is convenient as is, even though it is labelled as a “stack” only.

exception ContextError

Bases: Exception

Notifies a scenario stack error.

__init__()

Defines the error message.

__init__()

Initializes an empty scenario execution stack.

building

Instances under construction.

__scenario_executions

Scenario execution stack.

The first item defines the main_scenario. The subscenarios (if any) then follow.

history

History of scenario executions.

Main scenario executions only. In the chronological order.

pushscenarioexecution(scenario_execution)

Adds a scenario execution instance in the scenario execution stack.

Parameters:

scenario_execution – Scenario execution to set on top of the scenario execution stack.

popscenarioexecution()

Removes the last scenario execution from the scenario execution stack.

Returns:

Scenario execution removed.

property size

Returns the size of the scenario execution stack.

Returns:

Number of scenario executions currently stacked.

property main_scenario_definition

Main scenario definition under execution.

Returns the reference of the top scenario definition under execution, whether subscenarios are being executed or not.

Almost equivalent to main_scenario_execution, but retrieves the scenario definition instance.

property main_scenario_execution

Main scenario execution instance.

Returns the reference of the top scenario execution instance, whether subscenarios are being executed or not.

Almost equivalent to main_scenario_definition, but retrieves the scenario execution instance.

ismainscenario(scenario)

Tells whether the given scenario corresponds to the main one under execution.

Parameters:

scenario – Scenario definition or scenario execution to check.

Returns:

True if the scenario corresponds to the main scenario, False otherwise.

property current_scenario_definition

Current scenario definition under execution.

The latest unterminated subscenario if any, i.e. the main scenario if no current sub-scenario.

Almost equivalent to current_scenario_execution, but retrieves the scenario definition instance.

property current_scenario_execution

Current scenario execution instance.

The latest unterminated subscenario if any, i.e. the main scenario if no current sub-scenario.

Almost equivalent to current_scenario_definition, but retrieves the scenario execution instance.

iscurrentscenario(scenario)

Tells whether the given scenario corresponds to the one on top of the scenario stack.

Parameters:

scenario – Scenario definition or scenario execution to check.

Returns:

True if the scenario corresponds to the main scenario, False otherwise.

property current_step_definition

Current step definition under execution.

Out of the current scenario.

Compared with current_step_execution, this method returns the step definition whatever the execution mode of the ScenarioRunner.

None if no current step definition under execution.

property current_step_execution

Current step execution instance.

Out of the current_step.

Compared with current_step_definition, this method may not return a step execution instance when the ScenarioRunner is building objects.

None if no current step execution instance.

property current_action_result_definition

Current action or expected result definition under execution.

Out of the current step definition or step execution.

None current action / expected result definition.

property current_action_result_execution

Current action or expected result execution instance.

Out of the current step execution.

None if no current action / expected result execution instance.

knownissue(__id, __message)
knownissue(message, level=None, id=None)

Registers a known issue in the current context.

raisecontexterror(error_message)

Raises an error about the scenario stack execution.

Displays error information about the current status of the stack for investigation purpose.

Parameters:

error_message – Error message.

Raises:

ScenarioStack.ContextError – Systematically.