sass-imobiliaria/backend/tests/conftest.py

34 lines
806 B
Python

import pytest
from app import create_app
from app.extensions import db as _db
@pytest.fixture(scope="session")
def app():
"""Create application for testing."""
flask_app = create_app("testing")
flask_app.config["TESTING"] = True
with flask_app.app_context():
_db.create_all()
yield flask_app
_db.drop_all()
@pytest.fixture(scope="function")
def db(app):
"""Provide a clean database for each test."""
with app.app_context():
yield _db
_db.session.rollback()
# Clean all tables
for table in reversed(_db.metadata.sorted_tables):
_db.session.execute(table.delete())
_db.session.commit()
@pytest.fixture(scope="function")
def client(app, db):
"""Create test client."""
return app.test_client()