Skip to content

Commit ca5caa7

Browse files
committed
Use os.path.sep
1 parent ae4e75b commit ca5caa7

File tree

3 files changed

+12
-111
lines changed

3 files changed

+12
-111
lines changed

patches/0001-fix-detect-pytest-bdd-scenario-module-path-on-Window.patch

Lines changed: 0 additions & 99 deletions
This file was deleted.

pytest_reportportal/service.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@
9393
BACKGROUND_STEP_NAME = "Background"
9494

9595

96-
def _is_pytest_bdd_scenario_location(location_path: str) -> bool:
96+
def _is_pytest_bdd_scenario(location_path: str) -> bool:
9797
"""
9898
Return True if the pytest collection path points at pytest-bdd's scenario module.
9999
100100
``Item.location[0]`` uses OS-native separators (backslashes on Windows), so a
101101
plain suffix check with ``/`` is not portable. See #418.
102102
"""
103-
return location_path.replace("\\", "/").endswith("/pytest_bdd/scenario.py")
103+
return location_path.replace(os.path.sep, "/").endswith("/pytest_bdd/scenario.py")
104104

105105

106106
def trim_docstring(docstring: str) -> str:
@@ -917,7 +917,7 @@ def start_pytest_item(self, test_item: Optional[Item] = None):
917917
if not self.__started():
918918
self.start()
919919

920-
if PYTEST_BDD and _is_pytest_bdd_scenario_location(test_item.location[0]):
920+
if PYTEST_BDD and _is_pytest_bdd_scenario(test_item.location[0]):
921921
self._bdd_item_by_name[test_item.name] = test_item
922922
return
923923

@@ -938,7 +938,7 @@ def process_results(self, test_item: Item, report):
938938
if report.longrepr:
939939
self.post_log(test_item, report.longreprtext, log_level="ERROR")
940940

941-
if PYTEST_BDD and _is_pytest_bdd_scenario_location(test_item.location[0]):
941+
if PYTEST_BDD and _is_pytest_bdd_scenario(test_item.location[0]):
942942
return
943943

944944
leaf = self._tree_path[test_item][-1]
@@ -1021,7 +1021,7 @@ def finish_pytest_item(self, test_item: Optional[Item] = None) -> None:
10211021
leaf = self._tree_path[test_item][-1]
10221022
self._process_metadata_item_finish(leaf)
10231023

1024-
if PYTEST_BDD and _is_pytest_bdd_scenario_location(test_item.location[0]):
1024+
if PYTEST_BDD and _is_pytest_bdd_scenario(test_item.location[0]):
10251025
del self._bdd_item_by_name[test_item.name]
10261026
return
10271027

tests/unit/test_service.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@
1515

1616
from delayed_assert import assert_expectations, expect
1717

18-
from pytest_reportportal.service import _is_pytest_bdd_scenario_location
18+
from pytest_reportportal.service import _is_pytest_bdd_scenario
1919

2020

21-
def test_is_pytest_bdd_scenario_location_posix_path():
21+
def test_is_pytest_bdd_scenario_posix_path():
2222
"""pytest-bdd scenario items use forward slashes in location on POSIX."""
2323
path = "/usr/lib/python3.12/site-packages/pytest_bdd/scenario.py"
24-
assert _is_pytest_bdd_scenario_location(path) is True
24+
assert _is_pytest_bdd_scenario(path) is True
2525

2626

27-
def test_is_pytest_bdd_scenario_location_windows_path():
27+
def test_is_pytest_bdd_scenario_windows_path():
2828
"""pytest-bdd scenario items use backslashes in location on Windows (#418)."""
2929
path = r"C:\Python312\Lib\site-packages\pytest_bdd\scenario.py"
30-
assert _is_pytest_bdd_scenario_location(path) is True
30+
assert _is_pytest_bdd_scenario(path) is True
3131

3232

33-
def test_is_pytest_bdd_scenario_location_regular_test_module():
33+
def test_is_pytest_bdd_scenario_regular_test_module():
3434
"""Regular tests must not be treated as pytest-bdd scenario glue."""
35-
assert _is_pytest_bdd_scenario_location("/project/tests/test_foo.py") is False
35+
assert _is_pytest_bdd_scenario("/project/tests/test_foo.py") is False
3636

3737

3838
def test_get_item_parameters(mocked_item, rp_service):

0 commit comments

Comments
 (0)