close

[Solved] Runtime: working outside of application context

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Runtime: working outside of application context in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Runtime: working outside of application context Error Occurs?

Today I get the following error Runtime: working outside of application context in python.

How To Solve Runtime: working outside of application context Error ?

  1. How To Solve Runtime: working outside of application context Error ?

    To Solve Runtime: working outside of application context Error You can probably also shove the app.app_context() call into a test setup method as well. Hope this helps.

  2. Runtime: working outside of application context

    To Solve Runtime: working outside of application context Error You can probably also shove the app.app_context() call into a test setup method as well. Hope this helps.

Solution 1

when I ran into a similar problem when using pytest.

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

import pytest
from src.app import app


@pytest.fixture
def app_context():
    with app.app_context():
        yield


def some_test(app_context):
    # <test code that needs the app context>

Solution 2

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.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read