[v3,20/28] framework/profile: Split try/except block

Submitted by Dylan Baker on Oct. 31, 2016, 5:50 p.m.

Details

Message ID f3b62271c938d418decd812a715a564eb230e0dd.1477936071.git-series.dylan@pnwbakers.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Piglit

Not browsing as part of any series.

Commit Message

Dylan Baker Oct. 31, 2016, 5:50 p.m.
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@intel.com>
---
 framework/profile.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/framework/profile.py b/framework/profile.py
index 63d7f86..1cd0c0d 100644
--- a/framework/profile.py
+++ b/framework/profile.py
@@ -390,15 +390,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):