From f8bfc6ceed3b6d059749c4baf2feec71a8211694 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 22 Jan 2012 00:28:47 -0500 Subject: - More informative error message when a ``config.include`` cannot find an ``includeme``. See https://github.com/Pylons/pyramid/pull/392. Closes #392. --- CHANGES.txt | 6 ++++++ pyramid/config/__init__.py | 8 +++++++- pyramid/tests/test_config/test_init.py | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 81f420a84..2a8515d01 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,12 @@ Next release ============ +Features +-------- + +- More informative error message when a ``config.include`` cannot find an + ``includeme``. See https://github.com/Pylons/pyramid/pull/392. + Bug Fixes --------- diff --git a/pyramid/config/__init__.py b/pyramid/config/__init__.py index 04f9b6fb5..57ab7e13a 100644 --- a/pyramid/config/__init__.py +++ b/pyramid/config/__init__.py @@ -704,7 +704,13 @@ class Configurator( c = self.maybe_dotted(callable) module = inspect.getmodule(c) if module is c: - c = getattr(module, 'includeme') + try: + c = getattr(module, 'includeme') + except AttributeError: + raise ConfigurationError( + "module %r has no attribute 'includeme'" % (module.__name__) + ) + spec = module.__name__ + ':' + c.__name__ sourcefile = inspect.getsourcefile(c) diff --git a/pyramid/tests/test_config/test_init.py b/pyramid/tests/test_config/test_init.py index 3aa2c7810..a866bed55 100644 --- a/pyramid/tests/test_config/test_init.py +++ b/pyramid/tests/test_config/test_init.py @@ -712,6 +712,11 @@ pyramid.tests.test_config.dummy_include2""", self.assertEqual(action['callable'], None) self.assertEqual(action['args'], test_config) + def test_include_with_module_defaults_to_includeme_missing(self): + from pyramid.exceptions import ConfigurationError + config = self._makeOne() + self.assertRaises(ConfigurationError, config.include, 'pyramid.tests') + def test_include_with_route_prefix(self): root_config = self._makeOne(autocommit=True) def dummy_subapp(config): -- cgit v1.2.3