[Piglit] [PATCH v2 1/6] framework/tests: add helper for checking for 3rd party modules
baker.dylan.c at gmail.com
baker.dylan.c at gmail.com
Fri Oct 23 18:17:19 PDT 2015
From: Dylan Baker <baker.dylan.c at gmail.com>
This little helper skips a test if a module isn't available.
Signed-off-by: Dylan Baker <dylanx.c.baker at 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.1
More information about the Piglit
mailing list