9393BACKGROUND_STEP_NAME = "Background"
9494
9595
96+ def _is_pytest_bdd_scenario (location_path : str ) -> bool :
97+ """
98+ Return True if the pytest collection path points at pytest-bdd's scenario module.
99+
100+ ``Item.location[0]`` uses OS-native separators (backslashes on Windows), so a
101+ plain suffix check with ``/`` is not portable. See #418.
102+ """
103+ return location_path .endswith (os .path .join ("pytest_bdd" , "scenario.py" ))
104+
105+
96106def trim_docstring (docstring : str ) -> str :
97107 """
98108 Convert docstring.
@@ -907,7 +917,7 @@ def start_pytest_item(self, test_item: Optional[Item] = None):
907917 if not self .__started ():
908918 self .start ()
909919
910- if PYTEST_BDD and test_item .location [0 ]. endswith ( "/pytest_bdd/scenario.py" ):
920+ if PYTEST_BDD and _is_pytest_bdd_scenario ( test_item .location [0 ]):
911921 self ._bdd_item_by_name [test_item .name ] = test_item
912922 return
913923
@@ -928,7 +938,7 @@ def process_results(self, test_item: Item, report):
928938 if report .longrepr :
929939 self .post_log (test_item , report .longreprtext , log_level = "ERROR" )
930940
931- if PYTEST_BDD and test_item .location [0 ]. endswith ( "/pytest_bdd/scenario.py" ):
941+ if PYTEST_BDD and _is_pytest_bdd_scenario ( test_item .location [0 ]):
932942 return
933943
934944 leaf = self ._tree_path [test_item ][- 1 ]
@@ -1011,7 +1021,7 @@ def finish_pytest_item(self, test_item: Optional[Item] = None) -> None:
10111021 leaf = self ._tree_path [test_item ][- 1 ]
10121022 self ._process_metadata_item_finish (leaf )
10131023
1014- if PYTEST_BDD and test_item .location [0 ]. endswith ( "/pytest_bdd/scenario.py" ):
1024+ if PYTEST_BDD and _is_pytest_bdd_scenario ( test_item .location [0 ]):
10151025 del self ._bdd_item_by_name [test_item .name ]
10161026 return
10171027
0 commit comments