7

I got a problem when I tried to test a flask app that I can not access the g variable.

The api which is gonna tested looks like this:

user = query_object.get(g.user_id)   # here the exception raises

When I run the test, it raises:

NameError: global name 'g' is not defined
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
streethacker
  • 308
  • 5
  • 13

1 Answers1

11

What are your imports? You should try and add

from flask import g

Or, if you're using Quart

from quart import g
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
Vladimir T.
  • 199
  • 4