I'm using app_globals out of requests threads context as well, and found
that easiest way to fix it is to push app_globals into according
StackRegistry in load_environment:
config/environment.py:
# Setup cache object as early as possible
import pylons
pylons.cache._push_object(config['pylons.app_globals'].cache)
# Create the Mako TemplateLookup, with the default auto-escaping
config['pylons.app_globals'].mako_lookup = TemplateLookup(
directories=paths['templates'],
error_handler=handle_mako_error,
module_directory=os.path.join(app_conf['cache_dir'],
'templates'),
input_encoding='utf-8', default_filters=['escape'],
imports=['from webhelpers.html import escape'])
+ # Make app_globals be avaiable out of request context
+ pylons.app_globals._push_object(config['pylons.app_globals'])
In your func tests code you could then import it as
from pylons import app_globals
and it should be working.
On Fri, Jul 30, 2010 at 2:41 AM, Chris Angove <[email protected]>wrote:
> Working on upgrading my from Pylons 0.9.7 to 1.0. However, my tests
> now fail because the code (and the tests themselves) use app_globals
> which does not seem to be available. The code I use is:
>
>
>
> data_dir = config['pylons.app_globals'].lz_data_dir
>
>
>
> I use this in the test code itself and from within a module in app/
> lib.
> However when I run my unit tests:
>
>
>
> Traceback (most recent call last):
>
> File "/opt/wgen-3p/python26/lib/python2.6/site-packages/nose/
> case.py",
> line 186, in runTest
>
> self.test(*self.arg)
>
> File "/opt/wgen-3p/python26/lib/python2.6/site-packages/nose/
> util.py",
> line 634, in newfunc
>
> return func(*arg, **kw)
>
> File "/opt/wgen-3p/python26/lib/python2.6/site-packages/mock.py",
> line 196, in patched
>
> return func(*args, **keywargs)
>
> File
> "/home/cangove/code/landing-zone/src/landing_zone/tests/functional/
> test_
> wait_for_lzid.py", line 33, in test_one_collision
>
> find_results = [[LzFilePath(Status.uploaded, 'test', '1')], []]
>
> File
> "/home/cangove/code/landing-zone/src/landing_zone/lib/lz_paths.py",
> line 42, in __init__
>
> self._data_dir = data_dir or
> config['pylons.app_globals'].lz_data_dir
>
> AttributeError: 'NoneType' object has no attribute 'lz_data_dir'
>
>
> So why is config['pylons.app_globals'] set to None? If app_globals is
> not usable in this context shouldn't it just not exist in the config
> object? Also why would this not be valid, I though using nostests with
> the -with-pylons loaded the config and thus globals up. Anyone know
> why this no longer works in Pylons 1.0? Workarounds?
>
> --
> 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]<pylons-discuss%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>
>
--
With best regards,
Daniel Kluev
--
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.