yselkowitz / rpms / pcs

Forked from rpms/pcs 10 months ago
Clone
Blob Blame History Raw
From c878e1d06d834f0beb5579158ea5b98c42965058 Mon Sep 17 00:00:00 2001
From: Yaakov Selkowitz <yselkowi@redhat.com>
Date: Mon, 10 Jul 2023 12:56:41 -0400
Subject: [PATCH] Fix DatatransferObjectTest for Python 3.12

This fixes a test error when run with Python 3.12:
```
Traceback (most recent call last):
  File "pcs_test/tier0/common/interface/test_dto.py", line 41, in test_has_all_subclasses_are_dataclasses
    _import_all(pcs.__path__)
  File "pcs_test/tier0/common/interface/test_dto.py", line 31, in _import_all
    loader.find_module(module_name).load_module(module_name)
    ^^^^^^^^^^^^^^^^^^
AttributeError: 'FileFinder' object has no attribute 'find_module'
```
Instead, use the spec-based APIs introduced in 3.4:

https://docs.python.org/3.12/library/importlib.html#importlib.machinery.FileFinder
https://docs.python.org/3.12/library/importlib.html#importlib.machinery.ModuleSpec
---
 pcs_test/tier0/common/interface/test_dto.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pcs_test/tier0/common/interface/test_dto.py b/pcs_test/tier0/common/interface/test_dto.py
index 4c3dcb8b..977f35c9 100644
--- a/pcs_test/tier0/common/interface/test_dto.py
+++ b/pcs_test/tier0/common/interface/test_dto.py
@@ -28,7 +28,7 @@ def _import_all(_path):
         if module_name.startswith("_pcs.snmp."):
             continue
         del is_pkg
-        loader.find_module(module_name).load_module(module_name)
+        loader.find_spec(module_name).loader.load_module(module_name)
 
 
 def _all_subclasses(cls):
-- 
2.41.0