librelist archives

« back to archive

Testing and flask.g

Testing and flask.g

From:
Geoffry
Date:
2011-03-18 @ 18:58
Hey guys,

I'm trying to setup some simple unit tests on my app following the
instructions here: http://flask.pocoo.org/docs/testing/

What I would like to do is:

def setUp(self):
self.app = project.app.test_client()
flask.g.db = createDb()

However flask.g does not seem to be accessible (perhaps because it's not a
'request')... my model currently assumes that the db is always in
flask.g.db... is there a best practice for this? Should I be doing something
differently in my tests to get flask.g.db to work or should I do something
different in my model?

Thanks,
G

Re: [flask] Testing and flask.g

From:
Steven Kryskalla
Date:
2011-03-18 @ 19:06
On Fri, Mar 18, 2011 at 2:58 PM, Geoffry <vitron@gmail.com> wrote:
> However flask.g does not seem to be accessible (perhaps because it's not a
> 'request')...

Try accessing it within test_request_context:

http://flask.pocoo.org/docs/testing/#other-testing-tricks

-Steve

Re: [flask] Testing and flask.g

From:
Adam Patterson
Date:
2011-03-18 @ 19:03
Not a direct answer, but I went through this struggle as well
recently. Have a look at the newsmeme[1] source. I was having issues
testing as well but looking at the source for that helped me get
started.

[1] https://github.com/danjac/newsmeme

On Fri, Mar 18, 2011 at 1:58 PM, Geoffry <vitron@gmail.com> wrote:
> Hey guys,
> I'm trying to setup some simple unit tests on my app following the
> instructions here: http://flask.pocoo.org/docs/testing/
> What I would like to do is:
> def setUp(self):
> self.app = project.app.test_client()
> flask.g.db = createDb()
> However flask.g does not seem to be accessible (perhaps because it's not a
> 'request')... my model currently assumes that the db is always in
> flask.g.db... is there a best practice for this? Should I be doing something
> differently in my tests to get flask.g.db to work or should I do something
> different in my model?
> Thanks,
> G