Created
January 4, 2022 22:40
-
-
Save yeboah326/5e19d2d793a3cb9802cea806b8bcf819 to your computer and use it in GitHub Desktop.
Configuration files for testing flask application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the code setup i use for testing flask applications with pytest