Well you are in fact asking to setup a fake request (as you want tg.request) and that's exactly what `/_test_vars` is for.
The fact that you rely on WebTest to trigger such endpoint is just for convenience, as far as you have access to a turbogears application you can tell the application to preserve a context (WebTest just wraps the Application). TurboGears provides a context manager that provides a fake context whenever you are inside it http://turbogears.readthedocs.io/en/latest/reference/classes.html#tg.util.webtest.test_context but for the same convenience reasons it depends on WebTest. By the way you don't need to create TestApp every time, you can set it up once and just get the `/_test_vars` whenever you need a turbogears context in current thread. I can easily modify test_context to not need WebTest if that's a major issue, but it will still require an app for which to setup the context as it's pretty hard to setup the context for an application without an application :D On Fri, Jan 20, 2017 at 1:22 PM, Ítalo Rossi <[email protected]> wrote: > +1 > > I also want to know how to accomplish this outside the request/response > life cycle. > > We have a few daemons that use ours util/libs/models and we had the same > problem with i18n. > > > > > > On Fri, Jan 20, 2017 at 8:55 AM, damien accorsi < > [email protected]> wrote: > >> Hi Alessandro, hi all, >> >> I come to you about an issue I'm facing on tracim development. >> Tracim is based on turbogears for all web stuff, it also includes wsgidav >> running through cherrypy in some daemon threads. >> >> The problem I'm facing is that I need to access tg context from requests >> managed by wsgidav (so the code is executed in threads managed by cherrypy, >> running on a daemon thread) >> >> I get the same error as explained on the documentation about gearbox >> command line operations : http://turbogears.readthedocs. >> io/en/latest/turbogears/gearbox.html?highlight=context# >> running-scripts-from-command-line >> >> TypeError: No object (name: context) has been registered for this thread >> >> >> I get exactly the same error. I can make my code to work if I setup >> test-like context : >> >> app = TestApp(...) >> app.get('/_test_vars') >> >> Unfortunnately, this does not solve my problem on a viable manner because >> it means a TestApp is setup on every webdav request. >> A way to fix this would be to override CherrypyWebServer and Cherrypy >> ThreadPool to setup the TestApp on each thread of the CherryPy ThreadPool. >> >> What a dirty way to implement this... >> >> Especially when you know that the only requirement I have is to translate >> lazy strings... >> >> Is there a way (elegant or not) to override gettext/ugettext used in TG >> stuff ? (currently translations are done through tg.translator.ugettext() >> which encapsulate a local ugettext function) >> >> We tried to monkey-patch this part of code unsuccessfully; and because >> the code is something like "meta-programmation code" it's difficult to >> understand how it works (and how it can or cannot be override) >> >> >> Note : if some refactoring is required on turbogears to make >> config/context usable outside tg application, we will help (but we dont >> know where to start our work) >> >> Thanks a lot. >> >> >> Damien >> >> -- >> 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. >> > > > > -- > Ítalo Rossi > > -- > 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. > -- 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.

