From: Dylan Baker <baker.dyla...@gmail.com>

This little helper skips a test if a module isn't available.

Signed-off-by: Dylan Baker <dylanx.c.ba...@intel.com>
---
 framework/tests/junit_backends_tests.py | 3 +--
 framework/tests/utils.py                | 9 +++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/framework/tests/junit_backends_tests.py 
b/framework/tests/junit_backends_tests.py
index 7d5a3fc..d0a6fd7 100644
--- a/framework/tests/junit_backends_tests.py
+++ b/framework/tests/junit_backends_tests.py
@@ -111,8 +111,7 @@ class TestJUnitSingleTest(TestJunitNoTests):
 
     def test_xml_valid(self):
         """backends.junit.JUnitBackend.write_test(): (once) produces valid 
xml"""
-        if etree.__name__ != 'lxml.etree':
-            raise SkipTest('Test requires lxml features')
+        utils.module_check('lxml')
         schema = etree.XMLSchema(file=JUNIT_SCHEMA)
         with open(self.test_file, 'r') as f:
             nt.ok_(schema.validate(etree.parse(f)), msg='xml is not valid')
diff --git a/framework/tests/utils.py b/framework/tests/utils.py
index 2a9370c..aaf782c 100644
--- a/framework/tests/utils.py
+++ b/framework/tests/utils.py
@@ -34,6 +34,7 @@ import tempfile as tempfile_
 import functools
 import subprocess
 import errno
+import importlib
 from contextlib import contextmanager
 
 try:
@@ -314,6 +315,14 @@ def binary_check(bin_, errno_=None):
                         e.returncode, errno_))
 
 
+def module_check(module):
+    """Check that an external module is available or skip."""
+    try:
+        importlib.import_module(module)
+    except ImportError:
+        raise SkipTest('Required module {} not available.'.format(module))
+
+
 def platform_check(plat):
     """If the platform is not in the list specified skip the test."""
     if not sys.platform.startswith(plat):
-- 
2.6.2

_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to