Skip to content
Snippets Groups Projects
Commit 26a4360e authored by Ximin Luo's avatar Ximin Luo
Browse files

Fix CI tests using python 3.6

3.6 is not yet default so some existing modules e.g. rpm are missing their
compiled components.
parent d09b8039
No related branches found
No related tags found
No related merge requests found
......@@ -30,5 +30,5 @@ class RpmFile(AbstractRpmFile):
difference = self.compare_bytes(other)
if not difference:
return None
difference.add_comment('Unable to find Python rpm module. Falling back to binary comparison.')
difference.add_comment('Unable to import Python rpm module. Falling back to binary comparison.')
return difference
......@@ -20,7 +20,7 @@
import pytest
import functools
import importlib
import importlib.util
import subprocess
from distutils.spawn import find_executable
......@@ -61,16 +61,22 @@ def get_supported_elf_formats():
('objdump', '--info'),
).decode('utf-8').splitlines())
def skip_unless_module_exists(name):
def module_does_not_exist(x):
try:
return importlib.util.find_spec(x) is None
except ImportError:
# Probing for submodules (eg. ``debian.deb822``) will attempt to
# import ``debian`` so we must handle that failing.
def module_is_not_importable(x):
try:
if importlib.util.find_spec(x) is None:
return True
# an existent module is not necessarily importable, e.g. if its child
# modules are not available, e.g. if we are running diffoscope using a
# non-default version of python, and the module uses extension modules
# that haven't been compiled for this version
__import__(x)
except ImportError:
# Probing for submodules (eg. ``debian.deb822``) will attempt to
# import ``debian`` so we must handle that failing.
return True
def skip_unless_module_exists(name):
return pytest.mark.skipif(
module_does_not_exist(name),
module_is_not_importable(name),
reason="requires {} module".format(name),
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment