A local stream object is an object that is stored in a dedicated structure that is bound to the current stream identifier. If you ask this structure for an object, it will use the current stream identifier to provide you with data unique to the current stream. See threading.local . You can get more details by entering import _threading_local; help(_threading_local) import _threading_local; help(_threading_local) into your interactive Python interpreter.
This means that whenever you use current_app , g or requests , you get a data structure that is safe to use in your stream, without having to worry about locking and other concurrency issues.
In normal operation, Flask processes incoming WSGI requests; for each such request, a request context is created for you; this is represented by g and request objects. If you try to use any of your representations without an incoming request (say, in your tests), the request object will not work and complains that there is no valid request context. Flask provides you with tools to create this context on demand in this case. See the Faking Resources and Context Documentation , as well as the Request Context chapter.
source share