File 053-tests-handle-collection_path-and-path-for-pytest_ignore_collect.patch of Package virt-manager

Subject: tests: handle "collection_path" and "path" for pytest_ignore_collect()
From: Pino Toscano ptoscano@redhat.com Mon Jun 30 14:20:36 2025 +0200
Date: Sun Jan 11 00:02:42 2026 +0100:
Git: 711275b92971647a087ef6e263d9125ced689e38

Starting from pytest 7, all the hooks that take a "path" (the legacy
path data type) as parameter (including pytest_ignore_collect()) now
take a "collection_path" (pathlib.Path), and the latter will be the
only option starting from pytest 9.

Since it looks like pluggy (the plugin/hook infrastructure used by
pytest underneath) does not support using "None" to accept extra
arguments in an hook, then the solution is to provide different hooks
according to the pytest version:
- the common implementation is switched to use pathlib.Path, looking
  like the new style of hook; once pytest 7 is assumed, this helper
  function can be switched back to be the actual hook
- declare pytest_ignore_collect() as supported by pytest, using
  "collection_path" as earlier as possible; pytest_ignore_collect()
  is either a no-op wrapper, or builds a pathlib.Path out of the legacy
  type
- pytest.version_tuple was added in pytest 7, so deal with its lack in
  older versions

All in all, there should be no behaviour change in the actual test
collection, and the deprecation warnings should be gone.

Signed-off-by: Pino Toscano <ptoscano@redhat.com>

diff --git a/tests/conftest.py b/tests/conftest.py
index 38cb09f1f..3c0731138 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -53,8 +53,7 @@ def pytest_addoption(parser):
     )
 
 
-def pytest_ignore_collect(path, config):
-    collection_path = pathlib.Path(path)
+def _impl_pytest_ignore_collect(collection_path, config):
     uitests_requested = config.getoption("--uitests")
 
     # Default --uitests to --verbosity=2
@@ -76,6 +75,17 @@ def pytest_ignore_collect(path, config):
         return True
 
 
+if getattr(pytest, "version_tuple", (0,)) >= (7,):
+
+    def pytest_ignore_collect(collection_path, config):
+        return _impl_pytest_ignore_collect(collection_path, config)
+
+else:
+
+    def pytest_ignore_collect(path, config):
+        return _impl_pytest_ignore_collect(pathlib.Path(path), config)
+
+
 def pytest_collection_modifyitems(config, items):
     def find_items(basename):
         return [i for i in items if os.path.basename(i.fspath) == basename]
openSUSE Build Service is sponsored by