alexkrechik / VSCucumberAutoComplete

Cucumber (Gherkin) Full Support Extension for VSCode
https://marketplace.visualstudio.com/items?itemName=alexkrechik.cucumberautocomplete
MIT License
331 stars 80 forks source link

Feature Request: Support auto complete steps written in pytest-bdd #318

Open jeshelmich opened 4 years ago

jeshelmich commented 4 years ago

Describe the feature I would like to be able to auto complete steps written in pytest-bdd

Expected behavior To elaborate, I am using the BDD framework for pytest called pytest-bdd (https://github.com/pytest-dev/pytest-bdd), where steps are written in Python

Step definition:

@given("I'm an author user")
def author_user():
    ...

@when(parsers.parse('I eat {eat:d} cucumbers'))
...
@given(parsers.parse("there are %start% cucumbers"))
@given(re.compile('I have (?P<n>\d+) cucumbers'))
@then(parsers.re(u"у мене є рядок який містить '{0}'".format(u'(?P<content>.+)')))

Gherkin step line

Given I'm an author
When I eat 3 cucumbers

When I eat <eat> cucumbers
Examples: Vertical
| eat   | 5  |
Akuukis commented 4 years ago

Workaround for some cases: use only parsers.parse everywhere, and add to settings:

{
    "cucumberautocomplete.gherkinDefinitionPart": "@(given|when|then|step)\\(parsers.parse\\(",
}

Weirdly, "@(given|when|then|step)\\((parsers.parse\\()?" for both parsers.parse and simply text doesn't work. Why?

jasonnance commented 3 years ago

The key seems to be using non-capturing groups. This covers text, parsers.parse, and parsers.cfparse for me:

@(given|when|then|step)(?:\\(parsers.(?:cf)?parse)?\\(

However, it still doesn't work in the following case when the step name isn't on the same line as the decorator:

@given(
    "my step"
)
def my_step():
    pass

I see the above a fair amount using black for formatting with longer step names and/or additional arguments to given().

mjaramillob0613 commented 2 years ago

@jeshelmich @jasonnance Did you use the "cucumberautocomplete.customParameters" for the parameter ? (?P.+)

TheRealFaner commented 1 year ago

I was upgrade this regex. Now it will found steps with plain text and text with parsers.parse. "cucumberautocomplete.gherkinDefinitionPart": "@(given|when|then|step)\\((?:parsers.parse\\(|)",

haraldnh commented 1 year ago

For other people struggling with this, I found that setting "cucumberautocomplete.stepRegExSymbol": "'" (for single-quoted strings, change if you have double quotes in your python strings) makes it work also with target_fixture arguments on the same line. Not sure why this is works differently from the normal regex, though. (I was planning to do something more complex, but then it suddenly just started working.)

diasdm commented 6 months ago

Based on the comments in this thread - thank you all - here is the solution that ultimately worked (jumping to definition) for all the different kinds of steps I'm using.

My .vscode/settings.json:

{
    "cucumberautocomplete.steps": [
        "steps/**/*.py"
    ],
    "cucumberautocomplete.syncfeatures": "feature/**/*.feature",
    "cucumberautocomplete.gherkinDefinitionPart": "@(given|when|then|step)\\((?:parsers.parse\\(|)",
    "cucumberautocomplete.customParameters": [
        {
            "parameter": "\\n{table}",
            "value": ""
        },
    ],
}

Supported steps:

alfechner commented 5 months ago

@diasdm works well for me, thanks for putting that together.

Will pytest-bdd at some point be supported officially?