On Jul 1, 2:41 pm, Yang Zhang <[email protected]> wrote:
> When attempting various things from our unit tests, such as calling
> render_mako or calling pylons.url or looking up certain parameters in
> pylons.config, we've run into problems with the environment not being
> fully set up, such as "No object (name: tmpl_context or C) has been
> registered for this thread".
>
> So far, we've been reading through the pylons source and then hacking
> our way around each problem, such as by calling directly into mako's
> render method or manually calling pylons.config._push_object. Is there
> a better way to get a non-crippled environment in our tests? Thanks.
I use nose with the --with-pylons setting, then do this in
load_environment right before `return config` (I have the line
`testing = true` in my test.ini):
if asbool(config['testing']):
pylons.config._push_object(config)
url._push_object(URLGenerator(config['routes.map'], {}))
I haven't needed it, but you could add a line in there for
app_globals, too:
pylons.app_globals._push_object(config['pylons.app_globals'])
So, I guess that's not really "better", but it works and seems clean
enough to me.
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.