Parameters in step definitions
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 = speedYou 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 = speedAdd the step to your test scenarios providing the value for the parameter.
For more information about available parsers, refer to pytest-bdd documentation.
Last modified: 11 February 2024