scenario.stepdefinition module

Step definition.

class StepDefinition

Bases: StepUserApi, Assertions, Logger

Step definition management.

classmethod getinstance(index=None)

Expects and retrieves a step with its appropriate type.

Parameters:

index – Optional step index of the kind. Optional. See ScenarioDefinition.getstep() for more details.

Returns:

The expected step for the current scenario, typed with the final user step 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 step definition.

__init__(method=None)
Parameters:

method – Method that defines the step, when applicable. Optional.

scenario

Owner scenario.

Initially set with a void reference. Fixed when scenariodefinition.ScenarioDefinition.addsteps() is called.

method

Step method, if any.

location

Definition location.

description

Step description.

__action_result_definitions

List of actions and expected results that define the step.

executions

Step executions.

__repr__()

Canonical string representation.

__str__()

Returns a human readable representation of the step definition.

property name

Step name, i.e. the fully qualified name of the class or method defining it.

property number

Step definition number.

Number of this step definition within the steps defining the related scenario. Starting from 1, as displayed to the user.

addactionresult(*action_result_definitions)

Adds actions / expected results to the list defining the step.

Parameters:

action_result_definitions – Action / expected result definitions to add.

Returns:

self

property actions_results

Action / expected result list.

getactionresult(index)

Retrieves an ActionResultDefinition instance from its location.

Parameters:

index – Action/result definition index.

Returns:

Action/result definition instance.

step()

Calls method, when not overloaded.

This method should be overloaded by user step definition classes.

Otherwise, this base implementation of this method expects the method attribute to be set, and invokes it.

_abc_impl = <_abc_data object>
class StepDefinitionHelper

Bases: object

Step definition helper methods.

Avoids the public exposition of methods for internal implementation only.

__init__(definition)

Instanciates a helper for the given step definition.

Parameters:

definition – Step definition instance this helper works for.

matchspecification(step_specification)

Determines whether the given step specification matches the related step definition.

Parameters:

step_specification – Step specification to check.

Returns:

True when the specification matches the related step definition.

static specificationdescription(step_specification)

Returns a human readable representation of the step specification.

Parameters:

step_specification – Step specification to compute a string representation for.

Returns:

String representation.

saveinitknownissues()

Saves init known issues for the related step definition.

I.e. the known issues declared at the definition level, before the :meth:StepDefinition.step()` method has been called.

The appropriate call to this method is made in ScenarioRunner._buildscenario().

getinitknownissues()

Retrieves the known issue list saved by stashinitknownissues() for the related step definition.

Returns:

Init known issue list.

class StepMethods

Bases: object

Collection of static methods to help manipulating methods.

static _hierarchycount(logger, method)

Returns the number of classes in class hierarchy that have this method being declared.

Parameters:
  • logger – Logger to use for debugging.

  • method – Method to look for accessibility in class hierarchy.

Returns:

Count. The higher, the upper class the method is defined into.

Used by the sortbyhierarchythennames() and sortbyreversehierarchythennames() methods.

static _dispmethodlist(methods)

Computes a debug representation of a method list.

Parameters:

methods – Array of methods to debug.

Returns:

Debug representation.

static sortbynames(logger, methods)

Sorts an array of methods by method names.

Parameters:
  • logger – Logger to use for debugging.

  • methods – Array of methods to sort.

static sortbyhierarchythennames(logger, methods)

Sorts an array of methods by hierarchy at first, then by method names.

Parameters:
  • logger – Logger to use for debugging.

  • methods – Array of methods to sort.

Makes the methods defined in the higher classes be executed prior to those defined in the lower classes, i.e. makes the most specific methods be executed at last.

Formerly used by before-test and before-step steps.

static sortbyreversehierarchythennames(logger, methods)

Sorts an array of methods by reverse hierarchy first, then by method names.

Parameters:
  • logger – Logger to use for debugging.

  • methods – Array of methods to sort.

Makes the methods defined in the lower classes be executed prior to those defined in the upper classes, i.e. makes the most specific methods be executed at first.

Formerly used by after-test and after-step steps.