title: Flask+Pytest+SQLAlchemy: Can't create and drop tables when run pytest using flask-sqlalchemy
body: <p>when I run tests It succeeds to connect to the database, but it does not create tables. I think maybe there is a different way to create tables when I use flask-sqlalchemy, but I can't find the solution.</p>
  
  <p>This is app.py</p>
  
  <pre><code>db = SQLAlchemy()
  def create_app(config_name):
      app = Flask(__name__, template_folder='templates')
      app.wsgi_app = ProxyFix(app.wsgi_app)
      app.config.from_object(config_name)
      app.register_blueprint(api)
      db.init_app(app)
  
      @app.route('/ping')
      def health_check():
          return jsonify(dict(ok='ok'))
  
      @app.errorhandler(404)
      def ignore_error(err):
          return jsonify()
  
      app.add_url_rule('/urls', view_func=Shorty.as_view('urls'))
      return app
  </code></pre>
  
  <p>This is run.py</p>
  
  <pre><code>environment = environ['TINY_ENV']
  config = config_by_name[environment]
  app = create_app(config)
  
  
  if __name__ == '__main__':
      app.run()
  </code></pre>
  
  <p>This is config.py</p>
  
  <pre><code>import os
  
  basedir = os.path.abspath(os.path.dirname(__file__))
  
  
  class Config:
      """
      set Flask configuration vars
      """
      # General config
      DEBUG = True
      TESTING = False
      # Database
      SECRET_KEY = os.environ.get('SECRET_KEY', 'my_precious_secret_key')
      SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root@localhost:3306/tiny'
      SQLALCHEMY_TRACK_MODIFICATIONS = False
      SERVER_HOST = 'localhost'
      SERVER_PORT = '5000'
  
  
  class TestConfig(Config):
      """
      config for test
      """
      TESTING = True
      SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root@localhost:3306/test_tiny'
  
  config_by_name = dict(
      test=TestConfig,
      local=Config
  )
  
  key = Config.SECRET_KEY
  </code></pre>
  
  <p>This is models.py</p>
  
  <pre><code>from datetime import datetime
  from flask_sqlalchemy import SQLAlchemy
  
  db = SQLAlchemy()
  
  
  class URLS(db.Model):
      __tablename__ = 'urls'
  
      id = db.Column(db.Integer, primary_key=True)
      original_url = db.Column(db.String(400), nullable=False)
      short_url = db.Column(db.String(200), nullable=False)
      created_at = db.Column(db.DateTime, default=datetime.utcnow()
  </code></pre>
  
  <p>This is test config setting.</p>
  
  <pre><code>db = SQLAlchemy()
  
  
  @pytest.fixture(scope='session')
  def app():
      test_config = config_by_name['test']
      app = create_app(test_config)
  
      app.app_context().push()
      return app
  
  
  @pytest.fixture(scope='session')
  def client(app):
      return app.test_client()
  
  
  @pytest.fixture(scope='session')
  def init_db(app):
      db.init_app(app)
      db.create_all()
      yield db
      db.drop_all()
  </code></pre>