system-pri/backend/tests/conftest.py

39 lines
857 B
Python
Raw Normal View History

2022-05-15 21:20:05 +02:00
from typing import Generator
import pytest
from apiflask import APIFlask
2022-05-15 21:20:05 +02:00
from flask import Flask
2023-01-04 22:51:58 +01:00
from flask.ctx import AppContext
from flask.testing import FlaskClient
2022-05-15 21:20:05 +02:00
from app import create_app
from app.dependencies import db
2022-05-15 21:20:05 +02:00
@pytest.fixture()
2023-01-04 22:51:58 +01:00
def test_app() -> Generator[Flask, None, None]:
yield create_app("testing")
2022-05-15 21:20:05 +02:00
@pytest.fixture()
2023-01-04 22:51:58 +01:00
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