From 6f6e6df11692910aa985a517d84f126e68b26d88 Mon Sep 17 00:00:00 2001 From: Jan Reimer Date: Sun, 4 Dec 2022 19:58:03 +0100 Subject: [PATCH 1/2] Fix parameters parsing from "Scenario Outline" for pytest-bdd >= 5.0.0 --- allure-pytest-bdd/features/outline.feature | 14 +++++++------- allure-pytest-bdd/src/pytest_bdd_listener.py | 2 +- allure-pytest-bdd/src/utils.py | 12 +++--------- allure-pytest-bdd/test/outline_test.py | 2 -- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/allure-pytest-bdd/features/outline.feature b/allure-pytest-bdd/features/outline.feature index 2cb37e03..5058739d 100644 --- a/allure-pytest-bdd/features/outline.feature +++ b/allure-pytest-bdd/features/outline.feature @@ -16,9 +16,9 @@ Feature: Scenario outline And example_test.py with content: """ from pytest_bdd import scenario - from pytest_bdd import given, then, when + from pytest_bdd import given, then, when, parsers - @given(" step") + @given(parsers.parse("{first} step")) def given_step(first): pass @@ -26,7 +26,7 @@ Feature: Scenario outline def nope_step(): pass - @then("step with param") + @then(parsers.parse("step with {second} param")) def then_step(second): pass @@ -39,13 +39,13 @@ Feature: Scenario outline Then allure report has result for "Outline example" scenario Then this scenario has parameter "first" with value "Alpha" Then this scenario has parameter "second" with value "1" - Then this scenario contains "Given step" step - Then this scenario contains "Then step with <1> param" step + Then this scenario contains "Given Alpha step" step + Then this scenario contains "Then step with 1 param" step Then allure report has result for "Outline example" scenario Then this scenario has parameter "first" with value "Bravo" Then this scenario has parameter "second" with value "2" - Then this scenario contains "Given step" step - Then this scenario contains "Then step with <2> param" step + Then this scenario contains "Given Bravo step" step + Then this scenario contains "Then step with 2 param" step diff --git a/allure-pytest-bdd/src/pytest_bdd_listener.py b/allure-pytest-bdd/src/pytest_bdd_listener.py index 8c02ef08..9a4f5fac 100644 --- a/allure-pytest-bdd/src/pytest_bdd_listener.py +++ b/allure-pytest-bdd/src/pytest_bdd_listener.py @@ -64,7 +64,7 @@ def pytest_bdd_before_step(self, request, feature, scenario, step, step_func): parent_uuid = get_uuid(request.node.nodeid) uuid = get_uuid(str(id(step))) with self.lifecycle.start_step(parent_uuid=parent_uuid, uuid=uuid) as step_result: - step_result.name = get_step_name(request.node, step) + step_result.name = get_step_name(step) @pytest.hookimpl def pytest_bdd_after_step(self, request, feature, scenario, step, step_func, step_func_args): diff --git a/allure-pytest-bdd/src/utils.py b/allure-pytest-bdd/src/utils.py index e21f234a..9d960f40 100644 --- a/allure-pytest-bdd/src/utils.py +++ b/allure-pytest-bdd/src/utils.py @@ -7,14 +7,8 @@ from allure_commons.utils import format_exception -def get_step_name(node, step): - name = f"{step.keyword} {step.name}" - if hasattr(node, 'callspec'): - params = node.callspec.params - for key in params: - name = name.replace(f"<{key}>", f"<{{{key}}}>") - name = name.format(**params) - return name +def get_step_name(step): + return f"{step.keyword} {step.name}" def get_name(node, scenario): @@ -50,5 +44,5 @@ def get_pytest_report_status(pytest_report): def get_params(node): if hasattr(node, 'callspec'): - params = node.callspec.params + params = node.callspec.params.pop('_pytest_bdd_example', {}) return [Parameter(name=name, value=value) for name, value in params.items()] diff --git a/allure-pytest-bdd/test/outline_test.py b/allure-pytest-bdd/test/outline_test.py index fddfd11d..d176148a 100644 --- a/allure-pytest-bdd/test/outline_test.py +++ b/allure-pytest-bdd/test/outline_test.py @@ -1,8 +1,6 @@ from pytest_bdd import scenario -import pytest -@pytest.mark.skip(reason="https://github.com/pytest-dev/pytest-bdd/issues/447") @scenario("../features/outline.feature", "Scenario outline") def test_scenario_outline(): pass From 45e19fa494d5190a45a3565da439cc27d6935d16 Mon Sep 17 00:00:00 2001 From: Jan Reimer <68804379+janxen@users.noreply.github.com> Date: Tue, 17 Jan 2023 18:09:10 +0100 Subject: [PATCH 2/2] Update allure-pytest-bdd/src/utils.py Co-authored-by: Maxim <17935127+delatrie@users.noreply.github.com> --- allure-pytest-bdd/src/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/allure-pytest-bdd/src/utils.py b/allure-pytest-bdd/src/utils.py index 9d960f40..ac70aac2 100644 --- a/allure-pytest-bdd/src/utils.py +++ b/allure-pytest-bdd/src/utils.py @@ -44,5 +44,7 @@ def get_pytest_report_status(pytest_report): def get_params(node): if hasattr(node, 'callspec'): - params = node.callspec.params.pop('_pytest_bdd_example', {}) + params = dict(node.callspec.params) + outline_params = params.pop('_pytest_bdd_example', {}) + params.update(outline_params) return [Parameter(name=name, value=value) for name, value in params.items()]