Skip to content

Commit

Permalink
test: Remove test dbs after running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RamiAwar committed Mar 29, 2024
1 parent 73bbe1b commit fe21557
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion text2sql-backend/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
files: ^text2sql-backend/
exclude: 'docs|scripts|node_modules|\.git|\.tox|\.idea|min\.css|.*\.js|.*\.csv|.*\.svg|^frontend/packages/old|pnpm-lock\.yaml'
default_stages: [commit]
fail_fast: false
Expand Down Expand Up @@ -38,7 +39,7 @@ repos:
hooks:
- id: pytest
name: pytest
entry: PYTHONPATH=. poetry run pytest
entry: sh -c 'cd text2sql-backend && PYTHONPATH=. poetry run pytest .'
language: system
types: [python]
pass_filenames: false
Expand Down
7 changes: 7 additions & 0 deletions text2sql-backend/tests/api/test_connection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import pathlib

import pytest
import pytest_asyncio
Expand Down Expand Up @@ -70,6 +71,9 @@ async def test_connect_db(client: TestClient) -> None:
assert data["database"]
assert data["is_sample"] is False

# Delete database after tests
pathlib.Path("test.db").unlink(missing_ok=True)


@pytest.mark.asyncio
async def test_get_table_schemas(client: TestClient, sample_db: Connection) -> None:
Expand Down Expand Up @@ -162,3 +166,6 @@ async def test_update_connection(client: TestClient, sample_db: Connection) -> N
data = response.json()["data"]
assert data["connection"]["dsn"] == update_in["dsn"]
assert data["connection"]["name"] == update_in["name"]

# Delete database after tests
pathlib.Path("new.db").unlink(missing_ok=True)
3 changes: 3 additions & 0 deletions text2sql-backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ async def engine() -> AsyncGenerator[AsyncEngine, None]:
yield engine
await engine.dispose()

# Delete database after tests
pathlib.Path("test.sqlite3").unlink(missing_ok=True)


@pytest_asyncio.fixture
async def session(engine: AsyncEngine, monkeypatch: pytest.MonkeyPatch) -> AsyncGenerator[AsyncSession, None]:
Expand Down

0 comments on commit fe21557

Please sign in to comment.