[Zope3-checkins] SVN: zope.testing/trunk/src/zope/testing/testrunner/runner.py Provide better diagnostics when layer_from_name() fails.

Marius Gedminas marius at pov.lt
Fri Aug 1 08:01:51 EDT 2008


Log message for revision 89123:
  Provide better diagnostics when layer_from_name() fails.
  
  I wish I could write a unit test for this, but so far I can only reproduce it
  by running all of the Zope 3.4 KGS tests, and even then I get this error on
  only three buildbot slaves out of four.
  
  

Changed:
  U   zope.testing/trunk/src/zope/testing/testrunner/runner.py

-=-
Modified: zope.testing/trunk/src/zope/testing/testrunner/runner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/runner.py	2008-08-01 11:56:06 UTC (rev 89122)
+++ zope.testing/trunk/src/zope/testing/testrunner/runner.py	2008-08-01 12:01:51 UTC (rev 89123)
@@ -651,7 +651,16 @@
         return _layer_name_cache[layer_name]
     layer_names = layer_name.split('.')
     layer_module, module_layer_name = layer_names[:-1], layer_names[-1]
-    return getattr(import_name('.'.join(layer_module)), module_layer_name)
+    module_name = '.'.join(layer_module)
+    module = import_name(module_name)
+    try:
+        return getattr(module, module_layer_name)
+    except AttributeError, e:
+        # the default error is very uninformative:
+        #   AttributeError: 'module' object has no attribute 'DemoLayer'
+        # it doesn't say *which* module
+        raise AttributeError('module %r has no attribute %r'
+                             % (module_name, module_layer_name))
 
 
 def order_by_bases(layers):



More information about the Zope3-Checkins mailing list