pytest-dev / pytest-bdd

BDD library for the pytest runner
https://pytest-bdd.readthedocs.io/en/latest/
MIT License
1.31k stars 221 forks source link

Steps require careful indentation not to be interpreted as multiline #123

Closed lrowe closed 1 month ago

lrowe commented 9 years ago

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.

bubenkoff commented 9 years ago

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

lrowe commented 9 years ago

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.

bubenkoff commented 9 years ago

nice project indeed, i'll take a look

bubenkoff commented 9 years ago

@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?

lrowe commented 9 years ago

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?

bubenkoff commented 9 years ago

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

pydolan commented 8 years ago

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.

rogerrohrbach commented 2 years ago

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.

youtux commented 2 years ago

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

jsa34 commented 1 month ago

Added test to make sure this is handled correctly now we are using the official parser. If test is merged, I think this can be closed

youtux commented 1 month ago

yes, this is fixed in the upcoming release (using new parser)