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

feat(python): support for pypi parse syntax and string concatenation #236

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

neskk
Copy link

@neskk neskk commented Jan 15, 2025

🤔 What's changed?

Support the pypi-parse step definition matcher used by behave and pytest-bdd - both python frameworks.

  • Added support for string concatenation both for plain and pypi-parse syntaxes.
  • Added tree-sitter query to match pypi parse syntax:
    • @step(parsers.parse("step-def"))
    • @step(parse("step-def"))
    • @step(parse("step-" + "d" + "ef"))
    • @step(parse("step-def {date:valid_date}", custom_types))

⚡️ What's your motivation?

I'm currently using pytest-bdd for running cucumber tests, but because I'm using PyPi Parse for step-definitions, the cucumber-plugin won't recognize them.

Supersedes #206.
Closes #205.

🏷️ What kind of change is this?

  • ⚡ New feature (non-breaking change which adds new behaviour)

♻️ Anything particular you want feedback on?

I haven't been able to run the cucumber vscode extension, so I couldn't test it "in action".

I have modified the unit-test step-definitions to include at least one test for each different syntax.

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

@neskk
Copy link
Author

neskk commented Jan 20, 2025

@kieran-ryan The step-def syntax works but now the parameter type queries identify named parameters, e.g.: @when(parse("make a request to {url}")) as a parameter type.

@neskk
Copy link
Author

neskk commented Jan 21, 2025

@kieran-ryan any ideas on how can we differentiate expressions coming from "parse" definitions from standard cucumber expressions?

# cucumber
@step("a cucumber expressions {custom_param_type}")
# pytest-bdd
@step(parsers.parse("a pypi {param_name_not_a_type}"))
@step(parsers.parse("a pypi {param_name:param_type}"))

I don't know how we can support the named parameters in step-defs that use the pypi parse, at the same time we support custom param types.
These two approaches effectively use the same syntax with different meaning:

  • in pypi parse {xxx} is a named parameter
  • in cucumber expressions {xxx} is a parameter type
    Because of this, the step-defs with "parse" syntax are discovered and indexed, but they throw errors for not defining the parameter types.

@neskk
Copy link
Author

neskk commented Jan 27, 2025

I realized that Pytest-BDD 8.0.0+ adds support to the official gherkin-parser.
Update: I thought this new pytest-bdd version would support cucumber-expressions, but it still doesn't.

This MR still has a problem with Parameter Types. Even though the step-defs are picked up by the language-service, it fails to parse parameters on step-definitions. E.g.:

@when(parse("bla bla bla {arg1}"))
def bla_bla_bla(arg1: str):
  // do something with arg1

This fails with something like: ParameterType "arg1" not found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pytest-BDD parse matcher step definitions
2 participants