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

Setting up gherkinDefinitionPart for pytest-bdd #428

Open 8byr0 opened 2 years ago

8byr0 commented 2 years ago

Hello!

I am trying to setup this extension to work with pytest bdd. I already checked with no success:

For anyone wondering to do the same, here's what I got working so far:

Steps retrieval:

Match all tests located in __tests__ folders.

{
  // ...
  "cucumberautocomplete.steps": ["**/__tests__/**/*.py"],
  // ...
}

Parameters replacement

{
  // ...
  "cucumberautocomplete.customParameters": [
    {
      "parameter": "/\\{.*\\}/",
      "value": ".*"
    }
  ],  
// ...
}

Still not working

I'm blocking on steps autocomplete. Currently I have this regex: (also tried without setting this param)

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

This does the job for simple definitions like:

@given(
    "I am a verified user",
    target_fixture="user",
)
def verified_user():
    pass

@given("I am a single line step")
def single_line_step():
    pass

@when("I am a step with {param}")
def step_with_param():
    pass

But it does not work for steps like:

# No autocomplete at all
@given(
    parsers.parse('I am a multi line step with "{variable}"'),
    target_fixture="single_line_step",
)
def multi_line_step():
    pass

# No autocomplete at all
@given(parsers.parse('I am a single line step with "{variable}"'))
def single_line_step():
    pass

# Auto completes `Single step", target_fixture="mutation_result`
@when("Single step", target_fixture="mutation_result")
def single_step():
    pass

@jAdde proposed a solution here https://github.com/alexkrechik/VSCucumberAutoComplete/issues/373#issuecomment-801147736 but it's not very elegant and is definitely incompatible with any formatter.

# Put args on next line to make parser working
@given('a set of users', 
   target_fixture='users')
def impl()
   pass

Did anyone got to make this extension work with pytest-bdd without tricking?

alfechner commented 5 months ago

I'm looking into the same issue but had no success.

I'm wondering if it would be easier to have a setting that matches 2 groups instead of define multiple settings for parts of it. That would be way more flexible and easier to configure I guess.