pytest-bdd icon indicating copy to clipboard operation
pytest-bdd copied to clipboard

Steps require careful indentation not to be interpreted as multiline

Open lrowe opened this issue 9 years ago • 9 comments

Many Gherkin examples on the net indent And/But steps with an extra space:

Scenario: Indent my steps
    When I indent with 4 spaces
     And I indent with 5 spaces to line up

This breaks due to pytest-bdd using indentation of multiline steps: https://pytest-bdd.readthedocs.org/en/latest/#multiline-steps

It also makes feature files extremely sensitive to files with mixed tabs/spaces, such as the steps.feature in the pytest-bdd tests.

lrowe avatar Jun 08 '15 22:06 lrowe

not sure, it will require quotes or some other symbols to distinguish multiline steps, which is not nicer than having to stick to predefined format, which is better in many ways, i think

bubenkoff avatar Jun 08 '15 22:06 bubenkoff

Cucumber/Behat/Behave all go with the docstring approach.

I think there's a lot of value in maintaining compatibility with the cucumber gherkin standard, but changing existing parsing rules is not something to be done lightly either.

It might be interesting to experiment with https://github.com/nathforge/gherkin-parser as it claims to be tested against all Cucumber and Behave test cases.

lrowe avatar Jun 08 '15 23:06 lrowe

nice project indeed, i'll take a look

bubenkoff avatar Jun 08 '15 23:06 bubenkoff

@lrowe so we've looked and that parser, and it seems to be ok-ish but needs lots of improvements, and there's no guarantee they will be accepted by the owner. also to integrate it with pytest-bdd seems like a lot of work are you sure it worth the effort?

bubenkoff avatar Jun 23 '15 08:06 bubenkoff

I think the indentation sensitivity issue is worth addressing at some point, though I don't have a strong opinion on the best way of doing so.

Out of interest, what type of improvements do you think need to be made to that parser library?

lrowe avatar Jun 24 '15 20:06 lrowe

not sure, first of all, it seems a overengineered in part of the parser, and at the same time doesn't have useful data structure to traverse in reverse direction - say from step to scenario and feature. classes would be much better than just dicts for that, and that's why we used them in pytest-bdd but in general i agree it makes no sense to have multiple parsers of the same simple thing - gherkin language i feel i'll work on the integration

bubenkoff avatar Jun 24 '15 21:06 bubenkoff

FWIW, there's an official python gherkin parser that might make sense to use instead of pytest-bdd's own parser.

If you want to continue supporting the current multiline step format, then I suggest either adding a new option for users to optionally switch to the pystring/table format Gherkin uses, or maybe even change strict_gherkin to use the Gherkin format.

pydolan avatar Mar 18 '16 22:03 pydolan

I really miss the ability I had in behave to right-align Ands. And it's a keyword, no? Surely the existing parser can be made smarter.

rogerrohrbach avatar Sep 24 '22 23:09 rogerrohrbach

I'll keep this in mind when writing the new parser.

youtux avatar Sep 25 '22 08:09 youtux