Im writing test code with pytest for testing API written with python 3. But Im struggling with the below error message. The python code correctly works without pytest but the error message comes out only when executing pytest code. I dont think that the problems came from low level issues although it seems to be. To be honest, the real meaning behind this error does not make sense for me. The context also does not seem to be related with this problem this time. (http://flask-sqlalchemy.pocoo.org/contexts/)
Would anyone please give me some tips or hints for the solution ?
* I already tried to solve the issue based on this question('No application found. Either work inside a view function or push an application context.') but it did not work on this code.
The part of codes that might be related with the issue. (test_auth.py)
app = Flask(__name__)
app.config.from_object(test)
db_acs.init_app(app)
logger = logging.getLogger(__name__)
init_app(app, db_acs, logger)
Error
=========================================================================================== FAILURES ============================================================================================
____________________________________________________________________________________ test______________________________________________________________________________________
def test():
sqlpath = app.config['SQL_PATH']['getid']
input_id = 'xxx'
> rows = db_acs.dba(sqlpath, s1=input_id)
test_auth.py:68:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../xxx/xxx/db/dba.py:33: in dba
connection = db.engine.connect()
../../../.pyenv/versions/3.6.5/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py:877: in engine
return self.get_engine()
../../../.pyenv/versions/3.6.5/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py:886: in get_engine
app = self.get_app(app)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <SQLAlchemy engine=None>, reference_app = None
def get_app(self, reference_app=None):
"""Helper method that implements the logic to look up an
application."""
if reference_app is not None:
return reference_app
if current_app:
return current_app._get_current_object()
if self.app is not None:
return self.app
raise RuntimeError(
> 'No application found. Either work inside a view function or push'
' an application context. See'
' http://flask-sqlalchemy.pocoo.org/contexts/.'
)
E RuntimeError: No application found. Either work inside a view function or push an application context. See http://flask-sqlalchemy.pocoo.org/contexts/.