tests: allow specifying which tools are known missing using...

tests: allow specifying which tools are known missing using DIFFOSCOPE_TESTS_MISSING_TOOLS, to override a DIFFOSCOPE_TESTS_FAIL_ON_MISSING_TOOLS
Signed-off-by: Mattia Rizzolo's avatarMattia Rizzolo <mattia@debian.org>
parent 2e111824
......@@ -54,6 +54,16 @@ def skipif(*args, **kwargs):
if os.environ.get('DIFFOSCOPE_TESTS_FAIL_ON_MISSING_TOOLS', None) != '1':
return pytest.mark.skipif(*args, **kwargs)
missing_tools = os.environ.get(
'DIFFOSCOPE_TESTS_MISSING_TOOLS', ''
).split()
missing_tools.append('/missing') # special value used in tests
tools_required = kwargs.get('tools', ())
if not tools_required or any(
x for x in tools_required if x in missing_tools
):
return pytest.mark.skipif(*args, **kwargs)
msg = "{} (DIFFOSCOPE_TESTS_FAIL_ON_MISSING_TOOLS=1)".format(
kwargs['reason']
)
......@@ -74,12 +84,13 @@ def skip_unless_tools_exist(*required):
return skipif(
tools_missing(*required),
reason="requires {}".format(" and ".join(required)),
tools=required,
)
def skip_if_tool_version_is(tool, actual_ver, target_ver, vcls=LooseVersion):
if tools_missing(tool):
return skipif(True, reason="requires {}".format(tool))
return skipif(True, reason="requires {}".format(tool), tools=(tool,))
if callable(actual_ver):
actual_ver = actual_ver()
return skipif(
......@@ -87,12 +98,13 @@ def skip_if_tool_version_is(tool, actual_ver, target_ver, vcls=LooseVersion):
reason="requires {} != {} ({} detected)".format(
tool, target_ver, actual_ver
),
tools=(tool,),
)
def skip_unless_tool_is_at_least(tool, actual_ver, min_ver, vcls=LooseVersion):
if tools_missing(tool) and module_is_not_importable(tool):
return skipif(True, reason="requires {}".format(tool))
return skipif(True, reason="requires {}".format(tool), tools=(tool,))
if callable(actual_ver):
actual_ver = actual_ver()
return skipif(
......@@ -100,12 +112,13 @@ def skip_unless_tool_is_at_least(tool, actual_ver, min_ver, vcls=LooseVersion):
reason="requires {} >= {} ({} detected)".format(
tool, min_ver, actual_ver
),
tools=(tool,),
)
def skip_unless_tool_is_at_most(tool, actual_ver, max_ver, vcls=LooseVersion):
if tools_missing(tool) and module_is_not_importable(tool):
return skipif(True, reason="requires {}".format(tool))
return skipif(True, reason="requires {}".format(tool), tools=(tool,))
if callable(actual_ver):
actual_ver = actual_ver()
return skipif(
......@@ -113,6 +126,7 @@ def skip_unless_tool_is_at_most(tool, actual_ver, max_ver, vcls=LooseVersion):
reason="requires {} <= {} ({} detected)".format(
tool, max_ver, actual_ver
),
tools=(tool,),
)
......@@ -120,7 +134,7 @@ def skip_unless_tool_is_between(
tool, actual_ver, min_ver, max_ver, vcls=LooseVersion
):
if tools_missing(tool):
return skipif(True, reason="requires {}".format(tool))
return skipif(True, reason="requires {}".format(tool), tools=(tool,))
if callable(actual_ver):
actual_ver = actual_ver()
return skipif(
......@@ -129,6 +143,7 @@ def skip_unless_tool_is_between(
reason="requires {} >= {} >= {} ({} detected)".format(
min_ver, tool, max_ver, actual_ver
),
tools=(tool,),
)
......@@ -139,6 +154,7 @@ def skip_if_binutils_does_not_support_x86():
return skipif(
'elf64-x86-64' not in get_supported_elf_formats(),
reason="requires a binutils capable of reading x86-64 binaries",
tools=('objdump',),
)
......@@ -170,6 +186,7 @@ def skip_unless_module_exists(name):
return skipif(
module_is_not_importable(name),
reason="requires {} module".format(name),
tools=('{}_module'.format(name)),
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment