On Thu, Feb 09, 2017 at 11:52:50AM +0100, Mattia Rizzolo wrote:
> E   ImportError: No module named 'debian'

Hmm, looks like skip_unless_module_exists() needs to catch the
exception. Patch attached - I don't like the "skip" variable, so if you
know of a nicer way (the function needs to return a callable so you
can't use mark.skip AFAICS) then please do it.

The way I read the docs is that it should return None here; not sure why
it doesn't - bug in python?

BTW, maybe it would be nice if the 'debian' tests were run in
autopkgtest; add a test-dep on python3-debian?

Cheers,

-- 
Iain Lane                                  [ [email protected] ]
Debian Developer                                   [ [email protected] ]
Ubuntu Developer                                   [ [email protected] ]
From eaa0885689df96a5fe8139be42ea53009625bf6c Mon Sep 17 00:00:00 2001
From: Iain Lane <[email protected]>
Date: Thu, 9 Feb 2017 17:36:36 +0000
Subject: [PATCH] tests: Catch ImportError when looking to see if a module is
 installed

importlib.util.find_spec raises this exception when the module isn't
there.

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=854670
---
 tests/comparators/utils/tools.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tests/comparators/utils/tools.py b/tests/comparators/utils/tools.py
index f0a0113..e798ed8 100644
--- a/tests/comparators/utils/tools.py
+++ b/tests/comparators/utils/tools.py
@@ -62,7 +62,13 @@ def get_supported_elf_formats():
     ).decode('utf-8').splitlines())
 
 def skip_unless_module_exists(name):
+    try:
+        importlib.util.find_spec(name)
+        skip = False
+    except ImportError:
+        skip = True
+
     return pytest.mark.skipif(
-        importlib.util.find_spec(name) is None,
+        skip,
         reason="requires {} module".format(name),
     )
-- 
2.10.2

Attachment: signature.asc
Description: PGP signature

Reply via email to