diff --git a/CHANGELOG.md b/CHANGELOG.md index f545785..b63e098 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] ### Fixed +- Issue [#418](https://github.com/reportportal/agent-python-pytest/issues/418) parametrize marker IDs, by @drcrazy + +## [5.6.4] +### Fixed - Agent crash in certain `pytest-bdd` cases, by @HardNorth ## [5.6.3] diff --git a/pytest_reportportal/service.py b/pytest_reportportal/service.py index 685d8b5..b93d96b 100644 --- a/pytest_reportportal/service.py +++ b/pytest_reportportal/service.py @@ -93,6 +93,16 @@ BACKGROUND_STEP_NAME = "Background" +def _is_pytest_bdd_scenario(location_path: str) -> bool: + """ + Return True if the pytest collection path points at pytest-bdd's scenario module. + + ``Item.location[0]`` uses OS-native separators (backslashes on Windows), so a + plain suffix check with ``/`` is not portable. See #418. + """ + return location_path.endswith(os.path.join("pytest_bdd", "scenario.py")) + + def trim_docstring(docstring: str) -> str: """ Convert docstring. @@ -907,7 +917,7 @@ def start_pytest_item(self, test_item: Optional[Item] = None): if not self.__started(): self.start() - if PYTEST_BDD and test_item.location[0].endswith("/pytest_bdd/scenario.py"): + if PYTEST_BDD and _is_pytest_bdd_scenario(test_item.location[0]): self._bdd_item_by_name[test_item.name] = test_item return @@ -928,7 +938,7 @@ def process_results(self, test_item: Item, report): if report.longrepr: self.post_log(test_item, report.longreprtext, log_level="ERROR") - if PYTEST_BDD and test_item.location[0].endswith("/pytest_bdd/scenario.py"): + if PYTEST_BDD and _is_pytest_bdd_scenario(test_item.location[0]): return leaf = self._tree_path[test_item][-1] @@ -1011,7 +1021,7 @@ def finish_pytest_item(self, test_item: Optional[Item] = None) -> None: leaf = self._tree_path[test_item][-1] self._process_metadata_item_finish(leaf) - if PYTEST_BDD and test_item.location[0].endswith("/pytest_bdd/scenario.py"): + if PYTEST_BDD and _is_pytest_bdd_scenario(test_item.location[0]): del self._bdd_item_by_name[test_item.name] return diff --git a/setup.py b/setup.py index f2ba665..95f948d 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ from setuptools import setup -__version__ = "5.6.4" +__version__ = "5.6.5" def read_file(fname): diff --git a/tests/unit/test_service.py b/tests/unit/test_service.py index b914cde..f28e18a 100644 --- a/tests/unit/test_service.py +++ b/tests/unit/test_service.py @@ -13,8 +13,23 @@ """This module includes unit tests for the service.py module.""" +import os + from delayed_assert import assert_expectations, expect +from pytest_reportportal.service import _is_pytest_bdd_scenario + + +def test_is_pytest_bdd_scenario_path(): + """pytest-bdd scenario items use forward slashes in location on POSIX and backslashes on Windows.""" + path = os.path.join("project", "pytest_bdd", "scenario.py") + assert _is_pytest_bdd_scenario(path) is True + + +def test_is_pytest_bdd_scenario_regular_test_module(): + """Regular tests must not be treated as pytest-bdd scenario glue.""" + assert _is_pytest_bdd_scenario("/project/tests/test_foo.py") is False + def test_get_item_parameters(mocked_item, rp_service): """Test that parameters are returned in a way supported by the client."""