Sorry, I should have mentioned that I'm using a brand new Pylons 1.0rc1 project (setup via the go-pylons.py script). The nosetests are being run with the out-of-the-box configuration (setup.cfg: [nosetests] with-pylons = test.ini) and I haven't changed TestController.__init__(). Basically, I just setup the framework and added the tests I described in my post.
Should the testing environment explicitly set the value of pylons.config to the result of load_environment()? How would you recommend accessing the runtime configuration from a standalone utility that isn't doing full application requests? -Andres On Mar 26, 2:31 pm, Mike Orr <sluggos...@gmail.com> wrote: > On Fri, Mar 26, 2010 at 9:03 AM, andres <and...@octopart.com> wrote: > > Hi, > > > I'm in the process of upgrading to Pylons 1.0 and I have some > > questions about runtime configuration. > > > According to the documentation (http://pylonshq.com/docs/en/1.0/ > > configuration/) the proper way to access the runtime configuration is > > via the pylons.config object: > > > from pylons import config > > > This works fine within the context of a WSGI app instance but outside > > the context of an app instance (e.g. testing environment), the config > > object is a bare-bones pylons config rather than the runtime > > configuration I expect. For example, if I create a simple library > > function to test for the presence of a runtime config key: > > > # myapp/lib/util.py > > from pylons import config > > > def has_config_key(key): > > return key in config > > > then I see the following behavior when I run this test: > > > # myapp/tests/functional/test_runtimeconfig.py > > from myapp.tests import TestController > > from myapp.lib.util import has_config_key > > > class ConfigTest(TestController): > > def test_app(self): > > response = > > self.app.get(url(controller='proxy',action='util_has_config_key',key='sqlal > > chemy.ur')) > > self.assertEqual('True' in response.body, True) > > > def test_func(self): > > haskey = has_config_key('sqlalchemy.url') > > self.assertEqual(haskey, False) > > > This means that for code that depends on the runtime configuration but > > which I want to execute outside the context of an WSGI app instance I > > need to access the runtime configuration via a different method. One > > way around this problem is to avoid "pylons.config" and instead > > configure everything in myapp.config.environment.load_environment(). > > Maybe that is a better design pattern. Another option is to cache > > global_conf and local_conf in load_environment(). Before doing either > > of these things though, I wanted to make sure I wasn't missing > > something. > > > How does Pylons recommend accessing the runtime configuration? > > Are you calling nosetests with "--with-pylons=test.ini", or does > setup.cfg contain the equivalent in the [nosetests] section? Does > your TestController.__init__() method call paste.deploy.loadapp()? > These should be enough to set up the 'config' object, call > environment.py, and initialize the model. If your Pylons application > is old, you may want to upgrade it to add these features. > > Pylons 1.0 / 0.10 changes the way the config is initialized. > ``load_environment()`` returns it, so a standalone utility can access > it without having to initialize the globals. That may be useful if > you just need the config but aren't doing full application requests. > > Parsing the config manually is quite a hassle, as you can see from the > source to loadapp(). So you'd want to avoid that. You can parse it > using the standard ConfigParser, but it won't do some things Paste > does such as "%(here)s" interpolation and underscored keys. > > -- > Mike Orr <sluggos...@gmail.com> -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-disc...@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.