Parameters in step definitions
Available only in PyCharm Professional: download to try or compare editions
When writing BDD tests, you can reuse steps in a flexible way by creating step definitions with parameters.
Specify the parameter in the step name and then use it in the test function definition.
@given("Speed is <speed>") def set_car_speed(my_car, speed): my_car.speed = speed
You can use the pypi_parse parser and pass an optional type converter. For example:
@given(parsers.parse("Speed is {speed:d}")) def set_car_speed(my_car, speed): my_car.speed = speed
Add the step to your test scenarios providing the value for the parameter.
For more information about available parsers, refer to pytest-bdd documentation.
Thanks for your feedback!
Was this page helpful?