From 562d30cf59c0fcdde2bf57410b8a7d976fe1eb9e Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Tue, 16 Apr 2024 17:29:54 +0200 Subject: [PATCH] tools/test: shell out to python3 to check for libdnf5 We run tests using tox to set up environments for different python versions to test against. The problem is that when a test shells out to a python script, like osbuild-depsolve-dnf5, it's not run inside the environment but in the system environment. The `has_dnf5()` check returns False because it fails to import dnf5 in the tox environment, even though the script can be run and the test will succeed. Use `python3 -c "import libdnf5"` to decide if the script is runnable instead of using `importlib`. This doesn't solve the problem of our tests running python scripts in a different environment than the one (we think) we are testing, but it will enable tests of osbuild-depsolve-dnf5 for now. --- tools/test/test_depsolve.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/test/test_depsolve.py b/tools/test/test_depsolve.py index 389c6635..2c97862e 100644 --- a/tools/test/test_depsolve.py +++ b/tools/test/test_depsolve.py @@ -1,5 +1,4 @@ import configparser -import importlib import json import os import pathlib @@ -24,7 +23,7 @@ TEST_KEY = "-----BEGIN PGP PUBLIC KEY BLOCK-----\nTEST KEY\n" def has_dnf5(): - return bool(importlib.util.find_spec("libdnf5")) + return sp.run(["python3", "-c", "import libdnf5"], check=False).returncode == 0 def has_dnf():