scenario.scenariodefinition module

Scenario definition.

class MetaScenarioDefinition

Bases: ABCMeta

Meta-class for ScenarioDefinition.

So that it can be a meta-class for ScenarioDefinition, MetaScenarioDefinition must inherit from abc.ABCMeta (which makes it inherit from type by the way) because the StepUserApi base class inherits from abc.ABC.

static __new__(mcs, name, bases, attrs, **kwargs)

Overloads class definition of ScenarioDefinition class and sub-classes.

Sets MetaScenarioDefinition.InitWrapper instances in place of __init__() methods, in order to have ScenarioDefinition initializers enclosed with BuildingContext.pushscenariodefinition() / BuildingContext.popscenariodefinition() calls.

Parameters:
  • name – New class name.

  • bases – Base classes for the new class.

  • attrs – New class attributes and methods.

  • kwargs – Optional arguments.

class InitWrapper

Bases: object

Wrapper for __init__() methods of ScenarioDefinition instances.

Encloses the initializer’s execution with BuildingContext.pushscenariodefinition() / BuildingContext.popscenariodefinition() calls, so that the building context of scenario stack knows about the scenario definition being built.

__init__(init_method)

Stores the original __init__() method.

Parameters:

init_method – Original __init__() method.

init_method

Original __init__() method.

__get__(obj, objtype=None)

Wrapper descriptor: returns a __init__() bound method with obj.

Parameters:
  • obj – Optional instance reference.

  • objtype – Unused.

Returns:

Bound initializer callable (as long as obj is not None).

Inspired from: - https://docs.python.org/3/howto/descriptor.html - https://github.com/dabeaz/python-cookbook/blob/master/src/9/multiple_dispatch_with_function_annotations/example1.py

__call__(*args, **kwargs)

__init__() wrapper call.

Parameters:
  • args

    Positional arguments.

    First item should normally be the ScenarioDefinition instance the initializer is executed for.

  • kwargs – Named arguments.

Pushes the scenario definition to the building context of the scenario stack before the initializer’s execution, then removes it out after the initializer’s execution.

class ScenarioDefinition

Bases: StepUserApi, Assertions, Logger

Base class for any final test scenario.

See the quickstart guide.

classmethod getinstance()

Expects and retrieves the current scenario definition with its appropriate type.

Returns:

The current scenario definition instance, typed with the final user scenario definition class this method is called onto.

The “current” scenario is actually the one being executed or built.

Makes it possible to easily access the attributes and methods defined with a user scenario definition.

location

Definition location.

script_path

Script path.

name

Scenario name: i.e. script pretty path.

continue_on_error

Continue on error option.

Local configuration for the current scenario.

Prevails on ScenarioConfig.Key.CONTINUE_ON_ERROR (see ScenarioRunner._shouldstop()).

Not set by default.

__attributes

Scenario attributes (see ScenarioConfig.expectedscenarioattributes()).

__step_definitions

List of steps that define the scenario.

execution

Scenario execution, if any.

__repr__()

Canonical string representation.

__str__()

Human readable string representation of the scenario definition.

setattribute(name, value)

Defines an attribute for the scenario.

Parameters:
  • name – Attribute name.

  • value – Attribute value.

Returns:

self

getattribute(name)

Retrieves an attribute value defined with the scenario.

Parameters:

name – Attribute name.

Returns:

Attribute value.

Raises:

KeyError – When the attribute name is not defined.

getattributenames()

Retrieves all attribute names defined with the scenario.

Returns:

List of attribute names, sorted in alphabetical order.

section(section_description)

Adds a step section.

Parameters:

section_description – Description for the section.

Returns:

The section step just added.

addstep(step_definition)

Adds steps to the step list defining the scenario.

Parameters:

step_definition – Step definition to add.

Returns:

The step just added.

getstep(step_specification=None, index=None)

Finds a step definition.

Parameters:
  • step_specification – Step specification (see stepdefinition.StepSpecificationType), or None.

  • index – Step index in the matching list. Last item when not specified.

Returns:

Step definition found, if any.

expectstep(step_specification=None, index=None)

Expects a step definition.

When the step cannot be found, an exception is raised.

Parameters:
  • step_specification – Step specification (see stepdefinition.StepSpecificationType), or None.

  • index – Step index in the matching list. Last item when not specified.

Returns:

Expected step.

Raises:

KeyError – When the step definition could not be found.

property steps

Step list.

class ScenarioDefinitionHelper

Bases: object

Scenario definition helper methods.

Avoids the public exposition of methods for internal implementation only.

static getscenariodefinitionclassfromscript(script_path)

Retrieves the scenario definitions classes from a Python script.

Parameters:

script_path – Path of a Python script.

Returns:

Scenario definition classes, if any.

__init__(definition)

Instanciates a helper for the given scenario definition.

Parameters:

definition – Scenario definition instance this helper works for.

definition

Related scenario definition.

_logger

Make this class log as if it was part of the ScenarioRunner execution.

buildsteps()

Reads the scenario step list by inspecting the user scenario class, and feeds the scenario definition step list.