pytest-bdd
pytest-bdd copied to clipboard
pytest-bdd 5.0.0_Example table values with spaces are not handled
Hi Team,
I have updated pytest-bdd to version 5.0.0, as suggested in the [https://pytest-bdd.readthedocs.io/en/stable/#migration-of-your-tests-from-versions-4-x-x]I have changed the way we call scenario outline table values from <> to {} using parser.
In our example table we have a field name customer name which has a value of "Tony Max Jung", with the new approach of calling table values it only fetches Tony, basically ignores string after the space and assigns it to other parameters. Attached the screenshot.
` Scenario Outline: fill forms
Given I launch site abc
When user enters <customer_name>
Examples:
| customer_name | job |
| Tony Max Jung | Director of abc|
| Tony Max Jung | CEO of abc |`
It happens because of how pytest-bdd works with parameters: "When user enters <customer_name> <job>" is inlined with parameters and become: "When user enters Tony Max Jung Director of abc" which is parsed with a step like:
@given(parse("When user enters {customer_name} {job}")) def step_definition(customer_name, job)
In such case, parse doesn't know how exactly to fill two parameters. You could workaround this using width or precision templates as it's described here: https://pypi.org/project/parse/ or transform your step to include some separators like [], so your step will look like: "When user enters [<customer_name>] [<job>]" and step definition like: @given(parse("When user enters [{customer_name}] [{job}]")) def step_definition(customer_name, job)
Thanks for the response, I tried the above method you mentioned, I am getting the error, any idea, please
Error: parse() missing 1 required positional argument
"When user enters [<customer_name>] [<job>]"
and step definition like:
@given(parse("When user enters [{customer_name}] [{job}]"))
def step_definition(customer_name, job)
Could you please provide which parse was imported? Seems you have used parse directly but not wrapper around it, who is provided by pytest_bdd:
from pytest_bdd.parsers import parse
And by example was inaccurate because of gherkin keyword:
@when(parse("user enters [{customer_name}] [{job}]"))
def step_definition(customer_name, job)
Thanks a lot @elchupanebrej, it works like a charm with pytest_bdd.parsers import parse, now I can use pytest-bdd - 5.0.0 both values in example table and the step parameters at the same time.
Hi @elchupanebrej , I had to uninstall pytest-bdd-5.0.0 as it has a issue with allure reports and go back to Pytest-bdd-4.1.0. My question is I managed to use both example table values and parameters in single step using the method you suggested, I couldn't do the same with Pytest-bdd-4.1.0. Any advice, please.
In the below code, I consume role from the example table and Case ID from the step
Feature file details:
Then the user [<role>] validates the page including column names Case ID.
@then(parse("the user [{role}] validates the dashboard page including column names {Case ID}"))
def dashboard_page(role, Case ID):
Combining of <parameter> and {parsed_parameters} is not supported in pytest-bdd 4.x #293
I see, thanks @elchupanebrej for the quick response.
Please provide info how allure was failed
@elchupanebrej Here is the issue raised https://github.com/allure-framework/allure-python/pull/644.
Looks like the json file generated by allure along with pytest-bdd==5.0.0 is not compatible, we get error when we try to open the report using the command allure serve folder_path
Error message: Could not read test result file targetreports/6557fe86-9aff-4b34-9198-2a61facbdff6-result.json
Plugin versions: pytest-bdd==5.0.0 allure-pytest-bdd==2.9.45
allure report works fine with: pytest-bdd==4.1.0 allure-pytest-bdd==2.9.45
Closing this as the issue seemed to be resolved. Feel free to comment if it's not the case.