Skip to content

Latest commit

 

History

History
114 lines (79 loc) · 3.1 KB

description.rst

File metadata and controls

114 lines (79 loc) · 3.1 KB

Provide a description for a test case

Scenario description can be added in various ways:

  1. In a .feature file
  2. Dynamically in a step definition
  3. Dynamically in a hook (e.g., before_scenario or after_scenario)

Description in a feature file

The easiest way to add a description to a test is to specify it directly in the corresponding scenario in the .feature file. For example:

Feature: Allure description for behave tests
    Scenario: Description from a .feature file
        This scenario has a description.
        This description spans across multiple lines.

        Given noop

The step definition is trivial:

from behave import given

@given("noop")
def step_impl(context):
    pass

Dynamic description

A description can be specified dynamically with the allure.dynamic.description function. This is useful if you want to include runtime values in the description.

Description in a step definition

Let's suppose, we want to add a description to the following test:

Feature: Allure description for behave tests
    Scenario: Description from a step definition
        Given description is provided in a step definition

We can achieve that using the following step definition:

from behave import given
import allure

@given("description is provided in a step definition")
def step_impl(context):
    allure.dynamic.description(
        "This scenario has a description specified by the step definition"
    )

Description in a hook

It's also possible to add a description from a hook in the environment.py file.

Suppose we have the following feature file (and step definition is the same as in Description in a feature file):

Feature: Allure description for behave tests
    Scenario: Description from the before_scenario hook
        Given noop

    Scenario: Description from the after_scenario hook
        Given noop

We can provide a description in the environment.py like this:

import allure

def before_scenario(context, scenario):
    if "before_scenario" in scenario.name:
        allure.dynamic.description(
            "This scenario has a description specified in the "
            "before_scenario hook"
        )


def after_scenario(context, scenario):
    if "after_scenario" in scenario.name:
        allure.dynamic.description(
            "This scenario has a description specified in the "
            "after_scenario hook"
        )