Skip to content

Instantly share code, notes, and snippets.

@yeboah326
Created January 4, 2022 22:40
Show Gist options
  • Save yeboah326/5e19d2d793a3cb9802cea806b8bcf819 to your computer and use it in GitHub Desktop.
Save yeboah326/5e19d2d793a3cb9802cea806b8bcf819 to your computer and use it in GitHub Desktop.
Configuration files for testing flask application
import pytest
from api import create_app, db
@pytest.fixture
def app():
flask_app = create_app()
flask_app.app_context().push()
yield flask_app
@pytest.fixture
def client(app):
yield app.test_client()
from api import db
def truncate_db():
meta = db.metadata
for table in meta.sorted_tables[::-1]:
db.session.execute(table.delete())
db.session.commit()
@yeboah326
Copy link
Author

This is the code setup i use for testing flask applications with pytest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment