Open jeshelmich opened 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?
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()
.
@jeshelmich @jasonnance Did you use the "cucumberautocomplete.customParameters" for the parameter ?
(?P
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\\(|)",
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.)
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:
@given("simple step")
def a():
pass
cucumberautocomplete.customParameters
configuration)
@when(parsers.parse("step with table:\n{table}"))
def a(table):
pass
# fmt: skip
prevents black from formatting this line)
@then(parsers.parse('loooooooooooooooooooooooooooooooooooooooooong step "{text}"')) # fmt: skip
def a(text):
pass
target_fixture
(be sure to use '
for quoting)
@when(parsers.parse('step with table and target fixture:\n{table}'), target_fixture="a_fixture") # fmt: skip
def a(table):
pass
@diasdm works well for me, thanks for putting that together.
Will pytest-bdd
at some point be supported officially?
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:
Gherkin step line