-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
pytest-bdd parse step definition matcher #206
base: main
Are you sure you want to change the base?
Conversation
Hello @kieran-ryan, Found some time to help test this PR.
|
Hello @vianney-g, did you manage to test this locally? Are you using pytest-bdd parser syntax:
I wish to have support for pytest-bdd parser syntax: https://pytest-bdd.readthedocs.io/en/stable/#step-arguments, including support for custom param types. I can try to run some experiments locally, I just need to grab your changes and install the extension on my dev environment. |
hi @neskk , ty for your interest. I was just facing the bug with pytest_bdd and I was wondering how to fix it. Then I discovered your PR. Then I realized it may not match all the cases. I think the query should match the following steps definitions: import pytest_bdd
from pytest_bdd import given, parsers, when, then
from pytest_bdd.parsers import parse
@pytest_bdd.given(parse("a stub with stub_id exists"))
@given(parse("a stub with {stub_id} exists"))
@when(parsers.parse("a stub with {stub_id} exists"))
@then(parsers.parse("a stub with {stub_id} exists" + " then"))
def test_stub_exists(stub_id):
assert stub_id == "stub_1"
return stub_id
@not_a_step(parse("a stub with {stub_id} exists"))
def test_not_match(stub_id):
assert stub_id == "stub_1"
return stub_id Please forget my suggestions above. I made some tests locally, and I think the following approach is better to match all the cases (I am not a pro of treesitter queries, I am just playing with):
|
I never looked into treesitter and the TypeScript/node.JS environment is still a bit foreign to me. |
You can adapt the python test file to reflect the different approaches. This patch works for me: --- a/src/language/pythonLanguage.ts
+++ b/src/language/pythonLanguage.ts
@@ -95,46 +95,28 @@ export const pythonLanguage: Language = {
`(decorated_definition
(decorator
(call
- function: (identifier) @method
arguments: (argument_list (string) @expression)
- )
+ ) @method
)
(#match? @method "(given|when|then|step)")
) @root`,
// pytest-bdd
- `(decorator
- (call
- function: (identifier) @annotation-name
- arguments: (argument_list
- (call
- function: (attribute) @parser
- arguments: (argument_list
- [
- (string) @expression
- ]
- )
- )
- )
- )
- (#match? @annotation-name "given|when|then|step")
- (#match? @parser "parser")
- ) @root`,
- `(decorator
- (call
- function: (identifier) @annotation-name
- arguments: (argument_list
- (call
- function: (attribute) @parser
- arguments: (argument_list
- [
- (binary_operator) @expression
- ]
- )
- )
- )
+ `(decorated_definition
+ (decorator
+ (call
+ arguments:
+ (argument_list
+ (call
+ arguments:
+ (argument_list
+ [(_) @expression]
+ )
+ ) @args
+ ) @parse
)
- (#match? @annotation-name "given|when|then|step")
- (#match? @parser "parser")
+ ) @annotation-name
+ (#match? @annotation-name "given|when|then|step")
+ (#match? @parse "parse")
) @root`,
],
snippetParameters: {
diff --git a/test/language/testdata/python/StepDefinitions.py b/test/language/testdata/python/StepDefinitions.py
index cc61457..406e17e 100644
--- a/test/language/testdata/python/StepDefinitions.py
+++ b/test/language/testdata/python/StepDefinitions.py
@@ -1,19 +1,23 @@
"""Port of givens for testdata."""
from behave import step, given, when, then
+from pytest_bdd.parser import parse
+from pytest_bdd import parser
+import pytest_bdd
-@step("a {uuid}")
+
+@step(parse("a {uuid}"))
def step_given(context, uuid):
assert uuid
-@given("a {date}")
+@given(parser.parse("a {date}"))
def step_date(context, date):
assert date
-@when("a {planet}")
+@pytest_bdd.when("a {planet}")
def step_planet(context, planet):
assert planet |
Thanks for sharing the patch with your changes @vianney-g. The diff is against the main branch or the branch of this MR? Is your test flow like, run
|
Hey @neskk ! This is a patch for the branch of this PR. I can run the tests with |
So, I confirm that everything worked well on my side with |
🤔 What's changed?
parse
step definition matcher ofpytest-bdd
- which is also used bybehave
; both Python frameworks⚡️ What's your motivation?
🏷️ What kind of change is this?
♻️ Anything particular you want feedback on?
📋 Checklist:
This text was originally generated from a template, then edited by hand. You can modify the template here.