On Tue, Feb 14, 2017 at 8:48 AM, damien accorsi <
[email protected]> wrote:

>
> Actually, I feel like we try to use turbogears stuff "as a library" (so
> not in an execution context)... this is probably why it is difficult to
> "understand how to setup tgapp context".
>

That's not far away from what /_test_vars were created for, they have been
created for use cases like running scripts that use TG from command line.
The tgshell actually uses them to setup a proper TurboGears context and let
scripts run.
Practically the core of the TGShell is:

 # Load the wsgi app first so that everything is initialized right
wsgiapp = loadapp(config_name, relative_to=here_dir)
test_app = TestApp(wsgiapp)

# Make available the tg.request and other global variables
tresponse = test_app.get('/_test_vars')


> If you decide to develop something for an easier way to setup the context
> without "/_test_vars",  We can help, Alessandro. Let me know what we can do.
>

I made it possible to use `with test_context:` on a plain TGApp, it will
setup the context without going through a request dispatch, so it shouldn't
interfere with any WSGI middleware etc. But you will need the configured
TGApp instance. Which you can get through the `configure_new_app` hook.

Practically, once you git a reference to the TGApp, you can manually setup
a context for it through the new test_context implementation available in
https://github.com/TurboGears/tg2/blob/63d1fcfbc038dd58ac23c4948357d8ba5772c382/tg/util/webtest.py

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

Reply via email to