Skip to content

Commit 5469352

Browse files
janxendelatrie
authored andcommitted
Fix parameters parsing from "Scenario Outline" for pytest-bdd >= 5.0.0 (fixes allure-framework#636) (allure-framework#716)
Co-authored-by: Maxim <17935127+delatrie@users.noreply.github.com>
1 parent 39710fa commit 5469352

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

allure-pytest-bdd/features/outline.feature

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ Feature: Scenario outline
1616
And example_test.py with content:
1717
"""
1818
from pytest_bdd import scenario
19-
from pytest_bdd import given, then, when
19+
from pytest_bdd import given, then, when, parsers
2020
21-
@given("<first> step")
21+
@given(parsers.parse("{first} step"))
2222
def given_step(first):
2323
pass
2424
2525
@when("do nothing")
2626
def nope_step():
2727
pass
2828
29-
@then("step with <second> param")
29+
@then(parsers.parse("step with {second} param"))
3030
def then_step(second):
3131
pass
3232
@@ -39,13 +39,13 @@ Feature: Scenario outline
3939
Then allure report has result for "Outline example" scenario
4040
Then this scenario has parameter "first" with value "Alpha"
4141
Then this scenario has parameter "second" with value "1"
42-
Then this scenario contains "Given <Alpha> step" step
43-
Then this scenario contains "Then step with <1> param" step
42+
Then this scenario contains "Given Alpha step" step
43+
Then this scenario contains "Then step with 1 param" step
4444

4545
Then allure report has result for "Outline example" scenario
4646
Then this scenario has parameter "first" with value "Bravo"
4747
Then this scenario has parameter "second" with value "2"
48-
Then this scenario contains "Given <Bravo> step" step
49-
Then this scenario contains "Then step with <2> param" step
48+
Then this scenario contains "Given Bravo step" step
49+
Then this scenario contains "Then step with 2 param" step
5050

5151

allure-pytest-bdd/src/utils.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,8 @@ def get_name(node, scenario):
4040
from allure_commons.utils import format_exception
4141

4242

43-
def get_step_name(node, step):
44-
name = f"{step.keyword} {step.name}"
45-
if hasattr(node, 'callspec'):
46-
params = node.callspec.params
47-
for key in params:
48-
name = name.replace(f"<{key}>", f"<{{{key}}}>")
49-
name = name.format(**params)
50-
return name
43+
def get_step_name(step):
44+
return f"{step.keyword} {step.name}"
5145

5246

5347
def get_name(node, scenario):
@@ -83,7 +77,9 @@ def get_pytest_report_status(pytest_report):
8377

8478
def get_params(node):
8579
if hasattr(node, 'callspec'):
86-
params = node.callspec.params
80+
params = dict(node.callspec.params)
81+
outline_params = params.pop('_pytest_bdd_example', {})
82+
params.update(outline_params)
8783
return [Parameter(name=name, value=value) for name, value in params.items()]
8884

8985

0 commit comments

Comments
 (0)