Skip to content

Commit

Permalink
test: 테스트 코드에서 데이터베이스 관리 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
2jun0 committed Jan 25, 2024
1 parent 0b39709 commit 3600a0c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions data_scrapers/tests/private/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import pytest
from sqlalchemy.orm import Session

from tests.private.database import drop_tables, engine, init_database
from tests.private.database import create_tables, drop_tables, engine, init_database


@pytest.fixture(autouse=True)
def database():
init_database()
create_tables()
yield
drop_tables()
engine.dispose()


@pytest.fixture
Expand Down
7 changes: 6 additions & 1 deletion data_scrapers/tests/private/database.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from sqlalchemy import Table, create_engine
from sqlalchemy_utils import create_database, database_exists

import private.game.model # noqa: F401
import private.genre.model # noqa: F401
import private.screenshot.model # noqa: F401
from private.config import setting
from private.model import Base

Expand All @@ -15,8 +18,10 @@ def init_database():
if not database_exists(setting.DATABASE_URL):
create_database(setting.DATABASE_URL)


def create_tables():
Base.metadata.create_all(engine, get_tables(), checkfirst=True)


def drop_tables():
Base.metadata.drop_all(engine)
Base.metadata.drop_all(engine, get_tables())

0 comments on commit 3600a0c

Please sign in to comment.