PyCharm 2023.3 Help

Parameters in step definitions

When writing BDD tests, you can reuse steps in a flexible way by creating step definitions with parameters.

  1. 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
  2. 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
  3. Add the step to your test scenarios providing the value for the parameter.

    Parameter in a BDD test scenario

For more information about available parsers, refer to pytest-bdd documentation.

Last modified: 07 March 2024