pytest-bdd
pytest-bdd copied to clipboard
Wrong step executed in case of similar step definition expression
trafficstars
In case there are steps with similar test definition's expression the wrong one is being picked up and executed. Scenario: sample_scenario.feature:
Feature: Sample steps check
Scenario: Sample steps check
Given today is "Monday"
When something happened
Then summed "value_1" for each "key_1" of "collection_1" and summed "value_2" for each "key_2" of "collection_2" are equal
test_sample.py:
from pytest_bdd import given, when, then, scenarios, parsers
scenarios('sample_scenario.feature')
@given(parsers.parse('today is "{today_day}"'))
def given_today(today_day):
print('Today is', today_day)
@when('something happened')
def when_happened():
print('Something happened')
@then(parsers.parse('summed "{left_values}" of "{left_set}" and summed "{right_values}" of "{right_set}" are equal'))
def compare_summed_values(left_values, left_set, right_values, right_set):
print('Wrong step used!')
print('left_values', left_values, 'left_set', left_set, 'right_values', right_values, 'right_set', right_set)
assert False
@then(parsers.parse('summed "{left_val}" for each "{left_key}" of "{left_set}" '
'and summed "{right_val}" for each "{right_key}" of "{right_set}" are equal'))
def compare_agg_summed_values(left_val, left_key, left_set, right_val, right_key, right_set):
print('left_val', left_val, 'left_key', left_key, 'left_set', left_set, 'right_val', right_val,
'right_key', right_key, 'right_set', right_set)
assert True
Actual output - wrong step is executed and four of the arguments from the scenario are passed to two parameters from executed step:
---------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------
Today is Monday
Something happened
Wrong step used!
left_values value_1" for each "key_1 left_set collection_1 right_values value_2" for each "key_2 right_set collection_2
=============================================================== short test summary info ===============================================================
FAILED my-tests/test_sample.py::test_sample_steps_check - assert False
================================================================== 1 failed in 0.30s ==================================================================
Environment info: Python 3.7.4 pytest==6.2.5 pytest-bdd==4.1.0