File 054-tests-use-Node.path-when-available.patch of Package virt-manager

Subject: tests: use Node.path when available
From: Pino Toscano ptoscano@redhat.com Mon Jun 30 14:56:08 2025 +0200
Date: Sun Jan 11 00:02:42 2026 +0100:
Git: 206e79d501a8a2226595e766418ff4253d8b6ff0

pytest 7 adds a "path" attribute to the Node class, which is the base of
the Item class used for items passed to pytest_collection_modifyitems().

Hence use it when available, using an helper function that tries to use
it and fallbacks on the old "fspath".

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

diff --git a/tests/conftest.py b/tests/conftest.py
index 3c0731138..88a710fdd 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -87,8 +87,14 @@ else:
 
 
 def pytest_collection_modifyitems(config, items):
+    def item_path_basename(item):
+        try:
+            return item.path.name
+        except AttributeError:
+            return os.path.basename(item.fspath)
+
     def find_items(basename):
-        return [i for i in items if os.path.basename(i.fspath) == basename]
+        return [i for i in items if item_path_basename(i) == basename]
 
     # Move test_cli cases to the end, because they are slow
     # Move test_checkprops to the very end, because it needs to run
openSUSE Build Service is sponsored by