pytest-bdd
pytest-bdd copied to clipboard
--cucumberjson-expanded does not work for pytest.mark.parametrize
Step name does not contain argument value in scenario outline in Cucumber JSON report when I use @pytest.mark.parametrize decorator.
Version: python==3.7.3 pytest==5.1.2 pytest-bdd==3.2.1
# -- FILE: scenario_outline.feature
Scenario Outline: Outlined given, when, thens
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers
# -- FILE: scenario_outline_test.py
import pytest
from pytest_bdd import given, when, then, scenario
@pytest.mark.parametrize(['start', 'eat', 'left'],
[(15, 7, 8),
(15, 5., 10)])
@scenario(
'scenario_outline.feature',
'Outlined given, when, thens',
example_converters=dict(start=int, eat=int, left=int)
)
def test_outlined(start, eat, left):
pass
@given('there are <start> cucumbers')
def start_cucumbers(start):
return dict(start=start)
@when('I eat <eat> cucumbers')
def eat_cucumbers(start_cucumbers, eat):
start_cucumbers['eat'] = eat
@then('I should have <left> cucumbers')
def should_have_left_cucumbers(start_cucumbers, start, eat, left):
assert start - eat == left
assert start_cucumbers['start'] == start
assert start_cucumbers['eat'] == eat
I run the test with following options:
python -m pytest scenario_outline_test.py -s -vvv --cucumberjson=cucumber.json --cucumberjson-expanded
Here is my output from cucumber.json:
"steps": [
{
"keyword": "Given",
"name": "there are <start> cucumbers",
"line": 2,
"match": {
"location": ""
},
"result": {
"status": "passed",
"duration": 996589
}
},
It works fine when I use Example in the feature file.
Hello,
i have an issue and i think it is the same as you.
I try to generate a cucumberjson file by using :
py.test test_feature_sample.py --cucumberjson=cucumberjson.json --cucumberjson-expanded
I get the following error:
pytest_bdd\cucumber_json.py", line 111, in _format_name name = name.replace('<{}>'.format(param), value) TypeError: replace() argument 2 must be str, not
If i do not use " --cucumberjson-expanded" it works like a charm.
I think it is cause because i have a scenario defined as :
@scenario('....','....', example_converters=dict(stringvalue=str, intvalue=int, concat_value=str))
and then the following call fails (file cucumberjson.py):
def _format_name(self, name, keys, values):
for param, value in zip(keys, values):
name = name.replace('<{}>'.format(param), value)
return name
It fails because value is expected to be a string while it has been converted by example_converters property into an int. I am able to resolve my problem simply by updating the code to:
def _format_name(self, name, keys, values):
for param, value in zip(keys, values):
name = name.replace('<{}>'.format(param),str(value))
return name
I am not able to push my branch (403) so i cannot make a pull request.
Edit: 1st pull request created :D