From 74824aa3687db234499133544b35b135e64e571b Mon Sep 17 00:00:00 2001 From: "lauren n. liberda" Date: Wed, 30 Oct 2024 14:29:32 +0100 Subject: [PATCH] pytest: switch hook from path to collection_path solves PytestRemovedIn9Warning: The (path: py.path.local) argument is deprecated, please use (collection_path: pathlib.Path) https://docs.pytest.org/en/latest/deprecations.html#py-path-local-arguments-for-hooks-replaced-with-pathlib-path --- changelog.d/+pytest_collection_path.changed.md | 1 + test/unit/conftest.py | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 changelog.d/+pytest_collection_path.changed.md diff --git a/changelog.d/+pytest_collection_path.changed.md b/changelog.d/+pytest_collection_path.changed.md new file mode 100644 index 00000000..1cb3d463 --- /dev/null +++ b/changelog.d/+pytest_collection_path.changed.md @@ -0,0 +1 @@ +Switch a pytest hook from path to collection_path. diff --git a/test/unit/conftest.py b/test/unit/conftest.py index 15929bae..e8305def 100644 --- a/test/unit/conftest.py +++ b/test/unit/conftest.py @@ -64,13 +64,12 @@ def pytest_report_header(config): @pytest.hookimpl(tryfirst=True) -def pytest_ignore_collect(path, config): +def pytest_ignore_collect(collection_path, config): """Ignore all tests from subfolders for different apiver.""" - path = str(path) ver = config.getoption('--api') other_versions = [v for v in API_VERSIONS if v != ver] for other_version in other_versions: - if other_version + os.sep in path: + if other_version in collection_path.parts: return True return False