Skip to content

Add ability to make step names dynamic #737

@julian-west

Description

@julian-west

I'm submitting a ...

  • bug report
  • feature request
  • support request => Please do not submit support request here, see note at the top of this template.

What is the current behavior?

The name of the step is not dynamic and cannot be natively changed/updated during test execution. Unlike the test description (allure.dynamic.description), for example

What is the expected behavior?

Ability to update the name of the step during the test execution.

What is the motivation / use case for changing the behavior?

I am using allure-pytest-bdd and defining a markdown table as part of the step description. In the allure report the markdown table is automatically included as part of the step name and is presented as a 'wall of text' which is difficult to read for the user.

For example:

Feature: Joining logic
    Scenario: Join customers with orders
        Given I have a customers dataframe:
            | cusomterid | customername |
            | 1          | Company A    |
            | 2          | Company B    |
        And I have a orders dataframe:
            | orderid | orderamount | customerid 
            | 1 | 100 | 1 |
            | 2 | 200 | 2 |

        When I join the dataframes

        Then The resulting dataframe is:
            | customerid | customername | orderid | orderamount |
            | 1          | Company A    | 1       | 100         |
            | 2          | Company B    | 2       | 200         |

This is rendered on the Allure report as follows:

Screenshot 2023-03-28 at 09 18 34

The markdown table text is rendered on a single line which makes the descriptive test name (e.g. "I have a customers dataframe") difficult to read as the line is cluttered by the table.

My suggested work around was to add the markdown table as an Text attachment which is easy to read/format and then update the name of the step to remove the markdown table text. For example, just keep the first line -- "I have a customers dataframe".

However, it doesn't seem possible to update the name of the step dynamically as part of the test.

I would be very happy to work on a PR for this.

Please tell us about your environment:

  • Allure version: 2.13.5
  • Test framework: pytest-bdd==6.1.1
  • Allure adaptor: allure-pytest-bdd==2.13.1

Other information

Here is some example code for the above scenario

import functools

import allure
from pytest_bdd import given
from pytest_bdd import parsers
from pytest_bdd import scenarios
from pytest_bdd import then
from pytest_bdd import when

scenarios("../features/joins.feature")


def parse_data_table(text):
    parsed_text = [
        [x.strip() for x in line.split("|")]
        for line in [x.strip("|") for x in text.splitlines()]
    ]

    header, *data = parsed_text

    return [dict(zip(header, line)) for line in data]


def datatable(name, fixture="data"):
    formatted_str = "{name}\n{{{fixture}:DataTable}}".format(
        name=name,
        fixture=fixture,
    )
    data_table_parser = functools.partial(parse_data_table)

    return parsers.cfparse(formatted_str, extra_types=dict(DataTable=data_table_parser))


@given(datatable("I have a customers dataframe:"), target_fixture="customers")
def parse_customers_dataframe(data):
    # just saving dataframe as string for now, but would convert to pandas/spark
    allure.attach(str(data), "customers dataframe", allure.attachment_type.TEXT)

    # update step name as part of test to remove markdown table
    # e.g. allure.dynamic.step("I have a customers dataframe")
    return data




@given(datatable("I have a orders dataframe:"), target_fixture="orders")
def parse_orders_dataframe(data):
    # just saving dataframe as string for now, but would convert to pandas/spark
    allure.attach(str(data), "orders dataframe", allure.attachment_type.TEXT)
    return data


@when("I join the dataframes", target_fixture="joined_df")
def join_dataframes(customers, orders):
    # joining logic
    return customers


@then(datatable("The resulting dataframe is:"))
def final_dataframe(joined_df, data):
    allure.attach(str(data), "Joined dataframe", allure.attachment_type.TEXT)
    # make assertion of joined_df vs table provided in step description

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions