-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
34 lines (26 loc) · 895 Bytes
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm.session import close_all_sessions
from sqlalchemy_utils.functions import create_database, database_exists
from starlette.testclient import TestClient
from db.base import metadata
from main import app
@pytest.fixture(autouse=True)
def set_env_vars():
os.environ["TESTING"] = "True"
@pytest.fixture(scope="session", autouse=True)
def setup_db():
"""Fixture that returns provisions the test database and tables"""
engine = create_engine(url=os.getenv("DATABASE_URL_TEST"))
if not database_exists(url=engine.url):
create_database(url=engine.url)
metadata.create_all(bind=engine)
yield
close_all_sessions()
metadata.drop_all(bind=engine)
@pytest.fixture()
def test_app():
"""Fixture that returns the test app instance"""
client = TestClient(app)
yield client