39 lines
857 B
Python
39 lines
857 B
Python
from typing import Generator
|
|
|
|
import pytest
|
|
from apiflask import APIFlask
|
|
from flask import Flask
|
|
from flask.testing import FlaskClient
|
|
from flask.ctx import AppContext
|
|
|
|
from app import create_app
|
|
from app.dependencies import db
|
|
|
|
|
|
@pytest.fixture()
|
|
def test_app() -> Generator[Flask, None, None]:
|
|
yield create_app("testing")
|
|
|
|
|
|
@pytest.fixture()
|
|
def test_app_ctx_with_db(test_app) -> Generator[AppContext, None, None]:
|
|
with test_app.app_context() as ctx:
|
|
db.create_all()
|
|
yield ctx
|
|
|
|
|
|
@pytest.fixture()
|
|
def test_client() -> FlaskClient:
|
|
app = create_app("testing")
|
|
with app.app_context():
|
|
db.create_all()
|
|
return app.test_client()
|
|
|
|
|
|
@pytest.fixture()
|
|
def test_app_with_context() -> Generator[APIFlask, None, None]:
|
|
app = create_app("testing")
|
|
with app.app_context():
|
|
db.create_all()
|
|
yield app
|