Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to make step names dynamic #737

Open
1 of 3 tasks
julian-west opened this issue Mar 28, 2023 · 1 comment
Open
1 of 3 tasks

Add ability to make step names dynamic #737

julian-west opened this issue Mar 28, 2023 · 1 comment
Labels
task:new feature Requesting new capability or software feature theme:pytest-bdd

Comments

@julian-west
Copy link

julian-west commented Mar 28, 2023

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
@julian-west
Copy link
Author

I think this feature request is also related to: #726

@delatrie delatrie added theme:pytest-bdd task:new feature Requesting new capability or software feature labels Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task:new feature Requesting new capability or software feature theme:pytest-bdd
Projects
None yet
Development

No branches or pull requests

2 participants