Hi Mike,

I know I'm probably missing something really simple but I don't see
how to access the "app" variable. I see that "app.config" is being set
in middleware.py but how can I access the "app" outside of make_app()?

Also, that doesn't seem to solve the problem of accessing the runtime
config from a standalone utility that doesn't call make_app(). It
seems like this should should be a valid way of accessing modules
without setting up a WSGI app:

from paste.deploy import appconfig
from myapp.config.environment import load_environment

if __name__ == '__main__':
    # Initialize the environment
    conf = appconfig('config:development.ini', relative_to='.')
    load_environment(conf.global_conf, conf.local_conf)

    # Check runtime config
    from pylons import config
    assert config.has_key('mykey')

Regarding nosetests, my coworker had a problem running tests
individually as well. I'll look into it some more and post a message
to pylons-discuss if I'm still having problems. Incidentally, what
version of nostests are you using? I'm using 0.11.3.

-Andres

On Mar 26, 11:45 pm, Mike Orr <sluggos...@gmail.com> wrote:
> On Fri, Mar 26, 2010 at 6:14 PM, andres <and...@octopart.com> wrote:
> > Hi Mike,
>
> > Thanks for helping me figure out this problem. In case it helps,
> > here's a copy of the pylons project I setup for testing:
> >http://dl.dropbox.com/u/374620/myapp.tgz
>
> > I have a few more questions:
>
> > 1) How can I access "app.config"?
>
> > 2) Can I access "app.config" outside of a WSGI app instance? I'd like
> > to run scripts by loading the environment but not the app (http://
> > pylonshq.com/snippets/running_commands_with_the_app_environment).
>
> > 3) The out-of-the-box pylons project throws an error when you run
> > nosetests on a single file:
> > $ cd myapp/myapp/tests/functional
> > $ nosetest test_proxy.py
> >>>>     
> >>>> SetupCommand('setup-app').run([pylons.test.pylonsapp.config['__file__']])
> >>>> AttributeError: 'NoneType' object has no attribute 'config'
>
> Well, you're right about ``config["mykey"]`` not working in a test
> controller. I tried making a Pylons 1.0rc1 app and created a main
> controller, and tried to print ``config["mykey"]`` and
> ``app.config["mykey"]``.  Maybe it's a new bug.
>
> The answers to all your questions above are the same.  The ``config``
> returned by load_environment() is a Pylons configuration instance, and
> it's the same as ``app.config`` which is set at the bottom of
> middleware.py.  ``pylons.config`` is the same but it's wrapped in a
> StackedObjectProxy, which is a thread-safe, application-instance safe
> way of accessing it in a regular controller.  But if you have the
> config instance itself, you don't need the proxy.
>
> You can call load_environment or make_app() yourself but they won't do
> exactly what you want.  They don't parse the INI file. They expect you
> to have done that already and passed the settings in as keyword args.
> Only loadapp() parses the INI file.
>
> When I run nosetests, it passes the setup-app line.So whatever error
> you're getting in #3, I'm not getting.  But the error message suggests
> that 'pylons.test.pylonsapp' is None. Why that would be, I don't know.
>
> --
> 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.

Reply via email to