Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step definitions generated in Python require refactoring #160

Closed
kieran-ryan opened this issue Nov 12, 2023 · 0 comments · Fixed by #161
Closed

Step definitions generated in Python require refactoring #160

kieran-ryan opened this issue Nov 12, 2023 · 0 comments · Fixed by #161
Assignees
Labels
🐛 bug Defect / Bug python

Comments

@kieran-ryan
Copy link
Sponsor Member

kieran-ryan commented Nov 12, 2023

A step definition generated in Python from a gherkin step, can require the following refactorings:

  • Outdent by two spaces
  • Remove space between the parentheses (()) and the colon (:) beginning the function block
  • Remove trailing comma and space after context if there's no generated parameters

The unexpected indentation (as flagged by Pylance) prevents execution of Python code; and the remaining errors fail formatters and linters such as black and ruff.

👓 What did you see?

When generating a Python step definition from a gherkin step...

When I eat "<eat>" cucumbers

...the step definition is indented by two spaces and a space is present between the parentheses and the colon of the function declaration.

  @when('I eat {string} cucumbers')
  def step_when(context, string) :
      # This was autogenerated using cucumber syntax.
      # Please convert to use regular expressions, as Behave does not currently support Cucumber Expressions

Additionally, when generating a Python step definition from a gherkin step containing no parameters...

Then I should have many cucumber

...a trailing comma and space appear after context.

  @then('I should have many cucumber')
  def step_then(context, ) :
      # This was autogenerated using cucumber syntax.
      # Please convert to use regular expressions, as Behave does not currently support Cucumber Expressions

✅ What did you expect to see?

The step definition is appropriately indented without redundant spaces and commas; as below:

@then('I should have many cucumber')
def step_then(context):
    # This was autogenerated using cucumber syntax.
    # Please convert to use regular expressions, as Behave does not currently support Cucumber Expressions

📦 Which tool/library version are you using?

Version: 1.82.0 (Universal)
Commit: 8b617bd08fd9e3fc94d14adb8d358b56e3f72314
Date: 2023-09-06T22:09:41.364Z (2 mos ago)
Electron: 25.8.0
ElectronBuildId: 23503258
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin x64 20.6.0
Cucumber VSCode Extension: 1.8.0

🔬 How could we reproduce it?

  1. Open Visual Studio Code with the Cucumber extension running
  2. Create an empty Python step definition file inside the 'features' directory
  3. Create a feature file containing a step from one of the above examples
  4. Select the step, and click the quick fix to generate a step definition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug python
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant