Flask Test: preprocess_request(), dispatch_request()
I'm not an expert in Flask, so this answer might miss some points, but I think it's enough to help clarify your situation:
- If a
before_request
function returns something else thanNone
, it is taken as the view's response, so no more treatment happens, see preprocess_request's doc process_response
calls theafter_request
methods, it's called regardless of the response content (AFAIK)- As per the same doc linked above, I would say that
rv
is the first non-None
result received frombefore_request
, not the last, as as soon as a non-None
is returned, the processing stops.
At a glance, I would say that this is the order of things:
preprocess_request
: call thebefore_request
functions in order- As soon as one of them returns something different than
None
, stop calling the remaining ones and jump to (4) dispatch_request
: call the method associated to the routing rulemake_response
: prepare theResponse
object based on the previous result (here,rv
)process_response
: call theafter_request
functions with theResponse
object