Closed itspage closed 9 years ago
converters are for argumented steps if you mean something like:
from pytest_bdd import parsers
from pytest_bdd import given
@given(parsers.parse("I have a product with {base_price} "), converters=dict(base_price=int))
def i_have_a_product(base_price):
...
in this example with simple int, converter is not even necessary as parsers.parse can do conversion for you via {base_price:d}
The data for the parametrized steps comes from the plain text. Does it make sense to allow converters there as well?
I'm using a simple text step because I have examples, so my feature looks like:
Scenario Outline: Some Scenario
Given I have a product with price <base_price>
When I request the price
Then the price is <expected_price>
Examples:
| base_price | expected_price |
| 42 | 42 |
| 35 | 35 |
And my step looks like:
@given("I have a product with price <base_price>", converters=dict(base_price=int))
@olegpidsadnyi im about argumented, not parametrized steps
@itspage, ok so you use parametrized step and you need to use example_converters on scenario level:
@given("I have a product with price <base_price>")
...
@scenario('some file', 'Some Scenario', example_converters=dict(base_price=int))
...
as in example https://github.com/pytest-dev/pytest-bdd#scenario-outlines
The reason why converters for outlined scenarios are needed on scenario level, and not on step level is that parametrization table (example) is globally accessible during the scenario, and it's important to have it all converted before the execution
Got it, thank you.
I have the following given decorator for a scenario outline with examples.
@given("I have a product with price", converters=dict(base_price=int))
Inside the function, the converter hasn't run on base_price and it's still a string.