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.
This commit is contained in:
Achilleas Koutsou 2024-04-16 17:29:54 +02:00 committed by Simon de Vlieger
parent ffbf75073a
commit 562d30cf59

View file

@ -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():