title: Flask testing - "RuntimeError: No application found” when trying to connect with db with SQLAlchemy
body: <p>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. (<a href="http://flask-sqlalchemy.pocoo.org/contexts/" rel="nofollow noreferrer">http://flask-sqlalchemy.pocoo.org/contexts/</a>)</p>
  
  <blockquote>
    <p>Would anyone please give me some tips or hints for the solution ?</p>
  </blockquote>
  
  <p>＊ I already tried to solve the issue based on this question(<a href="https://stackoverflow.com/questions/46540664/no-application-found-either-work-inside-a-view-function-or-push-an-application">&#39;No application found. Either work inside a view function or push an application context.&#39;</a>) but it did not work on this code.</p>
  
  <p>The part of codes that might be related with the issue.
  (test_auth.py)</p>
  
  <pre><code>    app = Flask(__name__)
      app.config.from_object(test)
      db_acs.init_app(app)
      logger = logging.getLogger(__name__)
      init_app(app, db_acs, logger)
  </code></pre>
  
  <p>Error</p>
  
  <pre><code>=========================================================================================== FAILURES ============================================================================================
  ____________________________________________________________________________________ test______________________________________________________________________________________
  
      def test():
          sqlpath = app.config['SQL_PATH']['getid']
          input_id = 'xxx'
  
  &gt;       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 = &lt;SQLAlchemy engine=None&gt;, 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(
  &gt;           '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/.
  </code></pre>