I followed @brenns10 's answer 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):