RuntimeError: working outside of application context RuntimeError: working outside of application context flask flask

RuntimeError: working outside of application context


Flask has an Application Context, and it seems like you'll need to do something like:

def test_connection(self):    with app.app_context():        #test code

You can probably also shove the app.app_context() call into a test setup method as well. Hope this helps.


I followed the answer from @brenns10 when I ran into a similar problem when using pytest.

I followed the suggestion of putting it into test setup, this works:

import pytestfrom src.app import app@pytest.fixturedef app_context():    with app.app_context():        yielddef some_test(app_context):    # <test code that needs the app context>