# HG changeset patch # User Mads Kiilerich # Date 1566986857 -7200 # Node ID d68b77e4e4abf1229adc89072bf1c4bc346bd704 # Parent 3b54bcf6d12835d372709c4392b64e099d6cfc49 tg2: move routing mapper initialization from RootController class definition time to instantiation time Things happened to work before, despite unfortunate code executation at import time. TurboGears 2.4 changed something, so actual serving works, but pytest fails with: collecting ... ... data/env/lib/python2.7/site-packages/_pytest/config/__init__.py:463: in _importconftest raise ConftestImportFailure(conftestpath, sys.exc_info()) E ConftestImportFailure: (local('.../kallithea/tests/conftest.py'), (, KeyError('paths',), )) or more useful, if raising the real exception instead of obfuscating with ConftestImportFailure: ... kallithea/tests/conftest.py:15: in from kallithea.controllers.root import RootController kallithea/controllers/root.py:29: in class RootController(RoutedController, BaseController): kallithea/controllers/root.py:31: in RootController mapper = make_map(config) kallithea/config/routing.py:32: in make_map rmap = Mapper(directory=config['paths']['controllers'], data/env/lib/python2.7/site-packages/tg/configuration/tgconfig.py:28: in __getitem__ return self.config_proxy.current_conf()[key] E KeyError: 'paths' _importconftest <_pytest.config.PytestPluginManager object at 0x7f20c770a3d0> .../conftest.py In this example, in RootController, the global config object is at this time just: {'debug': False, 'package': None, 'i18n.lang': None, 'tg.strict_tmpl_context': True, 'tg.app_globals': None} Solved by moving the mapper initialization to __init__. diff -r 3b54bcf6d128 -r d68b77e4e4ab kallithea/controllers/root.py --- a/kallithea/controllers/root.py Fri Aug 23 21:29:01 2019 +0200 +++ b/kallithea/controllers/root.py Wed Aug 28 12:07:37 2019 +0200 @@ -28,7 +28,8 @@ # inheriting from its RoutedController class. class RootController(RoutedController, BaseController): - mapper = make_map(config) + def __init__(self): + self.mapper = make_map(config) - # the following assignment hooks in error handling - error = ErrorController() + # the following assignment hooks in error handling + self.error = ErrorController()