Skip to content

Commit c1a4b00

Browse files
janxendelatrie
andauthored
Fix parameters parsing from "Scenario Outline" for pytest-bdd >= 5.0.0 (fixes #636) (#716)
Co-authored-by: Maxim <[email protected]>
1 parent d667b5e commit c1a4b00

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
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/pytest_bdd_listener.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def pytest_bdd_before_step(self, request, feature, scenario, step, step_func):
6464
parent_uuid = get_uuid(request.node.nodeid)
6565
uuid = get_uuid(str(id(step)))
6666
with self.lifecycle.start_step(parent_uuid=parent_uuid, uuid=uuid) as step_result:
67-
step_result.name = get_step_name(request.node, step)
67+
step_result.name = get_step_name(step)
6868

6969
@pytest.hookimpl
7070
def pytest_bdd_after_step(self, request, feature, scenario, step, step_func, step_func_args):

allure-pytest-bdd/src/utils.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,8 @@
77
from allure_commons.utils import format_exception
88

99

10-
def get_step_name(node, step):
11-
name = f"{step.keyword} {step.name}"
12-
if hasattr(node, 'callspec'):
13-
params = node.callspec.params
14-
for key in params:
15-
name = name.replace(f"<{key}>", f"<{{{key}}}>")
16-
name = name.format(**params)
17-
return name
10+
def get_step_name(step):
11+
return f"{step.keyword} {step.name}"
1812

1913

2014
def get_name(node, scenario):
@@ -50,5 +44,7 @@ def get_pytest_report_status(pytest_report):
5044

5145
def get_params(node):
5246
if hasattr(node, 'callspec'):
53-
params = node.callspec.params
47+
params = dict(node.callspec.params)
48+
outline_params = params.pop('_pytest_bdd_example', {})
49+
params.update(outline_params)
5450
return [Parameter(name=name, value=value) for name, value in params.items()]
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from pytest_bdd import scenario
2-
import pytest
32

43

5-
@pytest.mark.skip(reason="https://github.com/pytest-dev/pytest-bdd/issues/447")
64
@scenario("../features/outline.feature", "Scenario outline")
75
def test_scenario_outline():
86
pass

0 commit comments

Comments
 (0)