[Piglit] [PATCH v2 20/26] framework/profile: Split try/except block

Dylan Baker dylan at pnwbakers.com
Thu Oct 27 21:31:48 UTC 2016


This will avoid catching AttributeErrors when importing, and only catch
them if mod.profile doesn't exist.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/profile.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/framework/profile.py b/framework/profile.py
index 914736d..5c849f1 100644
--- a/framework/profile.py
+++ b/framework/profile.py
@@ -377,15 +377,18 @@ def load_test_profile(filename):
     try:
         mod = importlib.import_module('tests.{0}'.format(
             os.path.splitext(os.path.basename(filename))[0]))
+    except ImportError:
+        raise exceptions.PiglitFatalError(
+            'Failed to import "{}", there is either something wrong with the '
+            'module or it doesn\'t exist. Check your spelling?'.format(
+                filename))
+
+    try:
         return mod.profile
     except AttributeError:
         raise exceptions.PiglitFatalError(
-            'There is not profile attribute in module {}.\n'
+            'There is no "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 run(profiles, logger, backend, concurrency):
-- 
git-series 0.8.10


More information about the Piglit mailing list