Skip to content

Commit ae4e75b

Browse files
committed
Fix issue 418: Detect pytest-bdd scenario module path on Windows
1 parent 08fad6c commit ae4e75b

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
From 08fad6c5527c5c3a79c0cd5f689569a796f1bdbe Mon Sep 17 00:00:00 2001
2+
From: drcrazy <hcb@wowhcb.ru>
3+
Date: Tue, 7 Apr 2026 22:09:10 +0300
4+
Subject: [PATCH] fix: detect pytest-bdd scenario module path on Windows (#418)
5+
6+
Item.location[0] uses backslashes on Windows, so the suffix check for
7+
pytest_bdd/scenario.py never matched and RP received duplicate items.
8+
9+
Normalize path separators before comparing the suffix.
10+
11+
Closes #418
12+
13+
Made-with: Cursor
14+
---
15+
pytest_reportportal/service.py | 16 +++++++++++++---
16+
tests/unit/test_service.py | 19 +++++++++++++++++++
17+
2 files changed, 32 insertions(+), 3 deletions(-)
18+
19+
diff --git a/pytest_reportportal/service.py b/pytest_reportportal/service.py
20+
index 685d8b5..39e42b2 100644
21+
--- a/pytest_reportportal/service.py
22+
+++ b/pytest_reportportal/service.py
23+
@@ -93,6 +93,16 @@ ALPHA_REGEX = re.compile(r"^\d+_*")
24+
BACKGROUND_STEP_NAME = "Background"
25+
26+
27+
+def _is_pytest_bdd_scenario_location(location_path: str) -> bool:
28+
+ """
29+
+ Return True if the pytest collection path points at pytest-bdd's scenario module.
30+
+
31+
+ ``Item.location[0]`` uses OS-native separators (backslashes on Windows), so a
32+
+ plain suffix check with ``/`` is not portable. See #418.
33+
+ """
34+
+ return location_path.replace("\\", "/").endswith("/pytest_bdd/scenario.py")
35+
+
36+
+
37+
def trim_docstring(docstring: str) -> str:
38+
"""
39+
Convert docstring.
40+
@@ -907,7 +917,7 @@ class PyTestService:
41+
if not self.__started():
42+
self.start()
43+
44+
- if PYTEST_BDD and test_item.location[0].endswith("/pytest_bdd/scenario.py"):
45+
+ if PYTEST_BDD and _is_pytest_bdd_scenario_location(test_item.location[0]):
46+
self._bdd_item_by_name[test_item.name] = test_item
47+
return
48+
49+
@@ -928,7 +938,7 @@ class PyTestService:
50+
if report.longrepr:
51+
self.post_log(test_item, report.longreprtext, log_level="ERROR")
52+
53+
- if PYTEST_BDD and test_item.location[0].endswith("/pytest_bdd/scenario.py"):
54+
+ if PYTEST_BDD and _is_pytest_bdd_scenario_location(test_item.location[0]):
55+
return
56+
57+
leaf = self._tree_path[test_item][-1]
58+
@@ -1011,7 +1021,7 @@ class PyTestService:
59+
leaf = self._tree_path[test_item][-1]
60+
self._process_metadata_item_finish(leaf)
61+
62+
- if PYTEST_BDD and test_item.location[0].endswith("/pytest_bdd/scenario.py"):
63+
+ if PYTEST_BDD and _is_pytest_bdd_scenario_location(test_item.location[0]):
64+
del self._bdd_item_by_name[test_item.name]
65+
return
66+
67+
diff --git a/tests/unit/test_service.py b/tests/unit/test_service.py
68+
index b914cde..69e646a 100644
69+
--- a/tests/unit/test_service.py
70+
+++ b/tests/unit/test_service.py
71+
@@ -15,6 +15,25 @@
72+
73+
from delayed_assert import assert_expectations, expect
74+
75+
+from pytest_reportportal.service import _is_pytest_bdd_scenario_location
76+
+
77+
+
78+
+def test_is_pytest_bdd_scenario_location_posix_path():
79+
+ """pytest-bdd scenario items use forward slashes in location on POSIX."""
80+
+ path = "/usr/lib/python3.12/site-packages/pytest_bdd/scenario.py"
81+
+ assert _is_pytest_bdd_scenario_location(path) is True
82+
+
83+
+
84+
+def test_is_pytest_bdd_scenario_location_windows_path():
85+
+ """pytest-bdd scenario items use backslashes in location on Windows (#418)."""
86+
+ path = r"C:\Python312\Lib\site-packages\pytest_bdd\scenario.py"
87+
+ assert _is_pytest_bdd_scenario_location(path) is True
88+
+
89+
+
90+
+def test_is_pytest_bdd_scenario_location_regular_test_module():
91+
+ """Regular tests must not be treated as pytest-bdd scenario glue."""
92+
+ assert _is_pytest_bdd_scenario_location("/project/tests/test_foo.py") is False
93+
+
94+
95+
def test_get_item_parameters(mocked_item, rp_service):
96+
"""Test that parameters are returned in a way supported by the client."""
97+
--
98+
2.53.0.windows.2
99+

0 commit comments

Comments
 (0)