Skip to content

Commit 04a9655

Browse files
authored
fix(pytest-bdd): compatibility with pytest-bdd 5 and 6 (allure-framework#851)
1 parent 3ea25a2 commit 04a9655

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

allure-pytest-bdd/src/utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def get_allure_description(item, feature, scenario):
6161
if value:
6262
return value
6363

64-
feature_description = resolve_description(feature.description)
65-
scenario_description = resolve_description(scenario.description)
64+
feature_description = extract_description(feature)
65+
scenario_description = extract_description(scenario)
6666
return "\n\n".join(filter(None, [feature_description, scenario_description]))
6767

6868

@@ -146,7 +146,9 @@ def iter_pytest_tags(item):
146146
yield LabelType.TAG, mark.name
147147

148148

149-
def resolve_description(description):
149+
def extract_description(obj):
150+
description = getattr(obj, "description", None)
151+
150152
if isinstance(description, str):
151153
return description
152154

tests/allure_pytest_bdd/acceptance/description_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from hamcrest import assert_that
23
from hamcrest import equal_to
34

@@ -6,6 +7,7 @@
67
from allure_commons_test.result import has_description_html
78

89
from tests.allure_pytest.pytest_runner import AllurePytestRunner
10+
from tests.e2e import version_lt
911

1012

1113
def test_description_decorator(allure_pytest_bdd_runner: AllurePytestRunner):
@@ -258,6 +260,10 @@ def given_noop():
258260
)
259261

260262

263+
@pytest.mark.skipif(
264+
version_lt("pytest_bdd", 7),
265+
reason="Pytest-BDD doesn't support scenario-level descriptions until v7",
266+
)
261267
def test_scenario_description(allure_pytest_bdd_runner: AllurePytestRunner):
262268
feature_content = (
263269
"""
@@ -341,6 +347,10 @@ def given_noop():
341347
)
342348

343349

350+
@pytest.mark.skipif(
351+
version_lt("pytest_bdd", 7),
352+
reason="Pytest-BDD doesn't support scenario-level descriptions until v7",
353+
)
344354
def test_feature_and_scenario_description(allure_pytest_bdd_runner: AllurePytestRunner):
345355
feature_content = (
346356
"""

tests/allure_pytest_bdd/acceptance/title_test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from hamcrest import assert_that
22
from hamcrest import anything
3+
from hamcrest import any_of
34

45
from allure_commons_test.report import has_test_case
56
from allure_commons_test.result import has_title
67
from allure_commons_test.result import has_step
78
from allure_commons_test.result import with_steps
89

910
from tests.allure_pytest.pytest_runner import AllurePytestRunner
11+
from tests.e2e import version_gte
1012

1113

1214
def test_title_decorator(allure_pytest_bdd_runner: AllurePytestRunner):
@@ -517,14 +519,20 @@ def then_pytest_param_used(bar):
517519
steps_content,
518520
)
519521

522+
# before pytest-bdd v6 parsed step args defined fixtures, which may conflict with target fixtures
523+
step3_matcher = "Target Fixture" if version_gte("pytest_bdd", 6) else any_of(
524+
"Target Fixture",
525+
"Lorem Ipsum",
526+
)
527+
520528
assert_that(
521529
allure_results,
522530
has_test_case(
523531
"sample.feature:Bar",
524532
with_steps(
525533
anything(),
526534
has_title("Lorem Ipsum"),
527-
has_title("Target Fixture"),
535+
has_title(step3_matcher),
528536
has_title("Outline"),
529537
has_title("Mark"),
530538
),

0 commit comments

Comments
 (0)