SVN: zope.testing/branches/3.5/src/zope/testing/testrunner.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 89132:
  Provide better diagnostics when layer_from_name() fails.
  
  Backported r89123 from trunk.
  
  

Changed:
  U   zope.testing/branches/3.5/src/zope/testing/testrunner.py

-=-
Modified: zope.testing/branches/3.5/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/branches/3.5/src/zope/testing/testrunner.py	2008-08-01 12:28:59 UTC (rev 89131)
+++ zope.testing/branches/3.5/src/zope/testing/testrunner.py	2008-08-01 12:30:25 UTC (rev 89132)
@@ -1564,7 +1564,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):
     """Order the layers from least to most specific (bottom to top)
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.