Skip to content

Commit 3a730e4

Browse files
marcbrossaissogetiMarc BROSSAISyoutux
authored
cast "values" as a string because it could be another type if using e… (#335)
* cast "values" as a string because it could be another type if using example converters * Test for int string and float value Co-authored-by: Marc BROSSAIS <[email protected]> Co-authored-by: Alessio Bogon <[email protected]>
1 parent 0d43cc4 commit 3a730e4

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

pytest_bdd/cucumber_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _serialize_tags(self, item):
9090

9191
def _format_name(self, name, keys, values):
9292
for param, value in zip(keys, values):
93-
name = name.replace("<{}>".format(param), value)
93+
name = name.replace("<{}>".format(param), str(value))
9494
return name
9595

9696
def _format_step_name(self, report, step):

tests/feature/test_cucumber_json.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,55 @@ def test_passing_outline():
280280
assert jsonobject[0]["elements"][0]["steps"][0]["name"] == "type str and value hello"
281281
assert jsonobject[0]["elements"][1]["steps"][0]["name"] == "type int and value 42"
282282
assert jsonobject[0]["elements"][2]["steps"][0]["name"] == "type float and value 1.0"
283+
284+
285+
def test_converters_dict_with_expand_option(testdir):
286+
"""Test step trace."""
287+
testdir.makefile(
288+
".ini",
289+
pytest=textwrap.dedent(
290+
"""
291+
[pytest]
292+
markers =
293+
feature-tag
294+
scenario-outline-passing-tag
295+
"""
296+
),
297+
)
298+
testdir.makefile(
299+
".feature",
300+
test=textwrap.dedent(
301+
"""
302+
@feature-tag
303+
Feature: One scenario outline, expanded to multiple scenarios
304+
305+
@scenario-outline-passing-tag
306+
Scenario: Passing outline
307+
Given intvalue <intvalue> and stringvalue <stringvalue> and floatvalue <floatvalue>
308+
309+
Examples: example1
310+
| intvalue| stringvalue | floatvalue |
311+
| 1 | hello | 1.0 |
312+
"""
313+
),
314+
)
315+
testdir.makepyfile(
316+
textwrap.dedent(
317+
"""
318+
import pytest
319+
from pytest_bdd import given, scenario
320+
321+
@given('intvalue <intvalue> and stringvalue <stringvalue> and floatvalue <floatvalue>')
322+
def type_type_and_value_value():
323+
return 'pass'
324+
325+
@scenario('test.feature', 'Passing outline', example_converters=dict(intvalue=int, stringvalue=str, floatvalue=float))
326+
def test_passing_outline():
327+
pass
328+
"""
329+
)
330+
)
331+
result, jsonobject = runandparse(testdir, "--cucumber-json-expanded")
332+
assert result.ret == 0
333+
334+
assert jsonobject[0]["elements"][0]["steps"][0]["name"] == "intvalue 1 and stringvalue hello and floatvalue 1.0"

0 commit comments

Comments
 (0)