-
Notifications
You must be signed in to change notification settings - Fork 221
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
Unable to Reuse Step with Scenario Outline Examples #514
Comments
from pytest_bdd.parsers import parse
from pytest_bdd.steps import when
@when(parse("Student list is filtered with {filter_value}"))
def filter_student_list(filter_value):
print(f"logic for filtering the list with: {filter_value}") |
We could reduce count of such questions after implementation of #467 |
I have updated the code as you mentioned and it still fails with same error:
Stepdef.py:
Scenario.feature:
|
Could you please provide info about:
step definitions must be placed at conftest.py or in test modules. |
Try rename the step definition file to 'test_scenario.py' and import the 'scanerios' method to define the relative location of your feature file or just move the method in your 'conftest.py'. |
I have a very simple setup
|
Okay I was able to run the test but it just literally prints the params which I set in feature file its not printing the values which I set in examples. Please see the screenshot attached feature file:
stepdefs:
|
Nice job! The parameters of each example are printed in the |
I was expecting that pytest should convert that <first_name> to my example values which is test_fn1 and test_fn2 in stepdef too. Basically my expected result should look like this: Given student list Also, I dnt want to go with third party library as I have some restrictions. |
Can we say its a bug on pytest side? |
Could you please confirm that you use pytest>4 |
please find the versions: pytest==6.2.3 |
Combining of rendered steps and step parameters has been released in pytest_bdd==5.0 . The main discussion could be found in #293 |
Thank you for replying, I already went through that discussion earlier and seems like its a missing a case what Im expecting here. Also, may be you execute my example scenario in your machine and let me know if its working for you. :) |
I confirm that its working in my end. Well let me test few more scenarios and will close if I dnt face any issues |
I have a situation where Im unable to reuse a step when using scenario outline. Below is an example
Example.feature
Scenario Outline:
Given I have Students list in database
When Student list is filtered with <last_name>
And Student list is filtered with <first_name>
And Student list is filtered with <student_age>
Then Student count is more than zero
Examples:
| last_name| first_name| student_age|
| xyz_ln | xyz_fn. | 20 |
| xyz_ln | fgh_fn. | 21 |
Stepdef.py
@when("Student list is filtered with <filter_value>")
def filter_student_list(context, filter_value):
printf(f"logic for filtering the list with: {filter_value}" )
Error:
When I execute the the above example. It throws stepdef not found error. Reason is in stepdef.py I have used variable <filter_value> as a generic name. But pytest expects that in feature file we need to use the same variable name. Can you please help me in resolving this?
The text was updated successfully, but these errors were encountered: