Skip to content

Latest commit

 

History

History
100 lines (79 loc) · 2.56 KB

attachment.rst

File metadata and controls

100 lines (79 loc) · 2.56 KB

Attachments

You can attach data and files to behave test results. An attachment can be added from a step definition function or from a hook. See examples below for more details.

Attach data from a step definition

The easiest way to add an attachment is to call the allure.attach function from a step definition:

Feature file:

Feature: Allure attachments in behave tests
    Scenario: Data attachment from step definitions
        Given a step that adds a named attachment
        And a step that adds a typed named attachment

Step definition file:

import allure
from behave import given

@given("a step that adds a named attachment")
def step_impl(context):
    allure.attach(
        "This is the attachment with the name 'step.txt'",
        name="step.txt"
    )

@given("a step that adds a typed named attachment")
def step_impl(context):
    allure.attach(
        (
            "[DEBUG] This attachment is named 'trace.log' and has TEXT "
            "document appearance"
        ),
        name="trace.log",
        attachment_type=allure.attachment_type.TEXT
    )

Attach file from a step definition

Call the allure.attach.file function to attach a file:

Feature file:

Feature: Allure attachments in behave tests
    Scenario: File attachment from a step definition
        Given a step that attaches a file

Step definition file:

import allure
from behave import given

@given("a step that attaches a file")
def step_impl(context):
    allure.attach.file(
        "./logs/web",
        name="web.log",
        attachment_type=allure.attachment_type.TEXT
    )

Attach from a hook

You can also attach data and files from a behave hook, e.g., from the after_scenario:

import allure

def after_scenario(context, scenario):
    allure.attach(
        "This attachment will appear on a scenario level",
        name="attachment.txt",
        attachment_type=allure.attachment_type.TEXT
    )