Skip to content

Pytest-bdd multiline steps are too dangerous #474

@theObserver1

Description

@theObserver1

From the documentation:

As Gherkin, pytest-bdd supports multiline steps (aka PyStrings). But in much cleaner and powerful way:
Step is considered as multiline one, if the next line(s) after it’s first line, is indented relatively to the first line. The step name is then >simply extended by adding further lines with newlines.`

While i agree this implementation is much cleaner than Gherkin, it is also far too dangerous. i have personally seen test cases where a six step BDD test case was treated as a single step by pytest-bdd because a tester mixed tabs and spaces before a step. Even worse, the test case was then passed because the first line was successfully parsed, executed and passed. The remaining lines were treated as a continuation of the first and ignored. We've come close to missing some major issues due to this implementation of multiline support.

As a workaround we now remove all whitepace and tabs before each GIVEN/WHEN/THEN/AND line before passing the feature file to pytest-bdd. It's just too dangerous otherwise.

Is it possible to throw an exception if a line starting with GIVEN/WHEN/THEN/AND is treated as a multiple line continuation of the previous step due the indentation? Or at least throw a warning? A warning message would also be welcome if indentations consists of spaces and tabs as this will likely cause issues with current multiline implementation ie the line may appear correctly aligned in JIRA etc but Python can treat the tabs differently than spaces and, at least in our case, steps are going to be ignored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions