[Piglit] [PATCH] framework: Catch trying to load a non-existant profile

Dylan Baker baker.dylan.c at gmail.com
Mon Jun 22 14:06:56 PDT 2015

Currently if one specifies a non-existant module (ie: piglit run
deqp_gles4 out), then an uncaught ImportError will be raised. This patch
fixes that by catching the exception and re-raising a PiglitFatalError.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
 framework/profile.py             | 11 +++++++++--
 framework/tests/profile_tests.py |  6 ++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/framework/profile.py b/framework/profile.py
index 66d7899..bce28b9 100644
--- a/framework/profile.py
+++ b/framework/profile.py
@@ -411,7 +411,7 @@ class TestProfile(object):
 def load_test_profile(filename):
-    """ Load a python module and return it's profile attribute
+    """Load a python module and return it's profile attribute.
     All of the python test files provide a profile attribute which is a
     TestProfile instance. This loads that module and returns it or raises an
@@ -419,7 +419,10 @@ def load_test_profile(filename):
     This method doesn't care about file extensions as a way to be backwards
     compatible with script wrapping piglit. 'tests/quick', 'tests/quick.tests',
-    and 'tests/quick.py' are all equally valid for filename
+    and 'tests/quick.py' are all equally valid for filename.
+    This will raise a FatalError if the module doesn't exist, or if the module
+    doesn't have a profile attribute.
     filename -- the name of a python module to get a 'profile' from
@@ -433,6 +436,10 @@ def load_test_profile(filename):
         raise exceptions.PiglitFatalError(
             'There is not profile attribute in module {}.\n'
             'Did you specify the right file?'.format(filename))
+    except ImportError:
+        raise exceptions.PiglitFatalError(
+            'There is no test profile called "{}".\n'
+            'Check your spelling?'.format(filename))
 def merge_test_profiles(profiles):
diff --git a/framework/tests/profile_tests.py b/framework/tests/profile_tests.py
index 2488e7b..765528e 100644
--- a/framework/tests/profile_tests.py
+++ b/framework/tests/profile_tests.py
@@ -52,6 +52,12 @@ def test_load_test_profile_no_profile():
+ at nt.raises(exceptions.PiglitFatalError)
+def test_load_test_profile_no_module():
+    """profile.load_test_profile: Trying to load a non-existant module exits"""
+    profile.load_test_profile('this_module_will_never_ever_exist')
 def test_load_test_profile_returns():
     """profile.load_test_profile: returns a TestProfile instance"""
     profile_ = profile.load_test_profile('sanity')

More information about the Piglit mailing list