SVN: zope.testing/trunk/src/zope/testing/testrunner/runner.py Provide better diagnostics when layer_from_name() fails.

Marius Gedminas <[email protected]>
Newsgroups gmane.comp.web.zope.zope3.cvs
Message-ID <[email protected]>
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):
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.