From fe2155767c4dfa67498d949fc80f00e1a9ea0924 Mon Sep 17 00:00:00 2001 From: Rami Date: Fri, 29 Mar 2024 15:02:08 +0100 Subject: [PATCH] test: Remove test dbs after running tests --- text2sql-backend/.pre-commit-config.yaml | 3 ++- text2sql-backend/tests/api/test_connection.py | 7 +++++++ text2sql-backend/tests/conftest.py | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/text2sql-backend/.pre-commit-config.yaml b/text2sql-backend/.pre-commit-config.yaml index e307f684..c723a0c8 100644 --- a/text2sql-backend/.pre-commit-config.yaml +++ b/text2sql-backend/.pre-commit-config.yaml @@ -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 @@ -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 diff --git a/text2sql-backend/tests/api/test_connection.py b/text2sql-backend/tests/api/test_connection.py index 0d9ad074..8d30349a 100644 --- a/text2sql-backend/tests/api/test_connection.py +++ b/text2sql-backend/tests/api/test_connection.py @@ -1,4 +1,5 @@ import logging +import pathlib import pytest import pytest_asyncio @@ -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: @@ -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) diff --git a/text2sql-backend/tests/conftest.py b/text2sql-backend/tests/conftest.py index b2d9fdd5..1954fd9c 100644 --- a/text2sql-backend/tests/conftest.py +++ b/text2sql-backend/tests/conftest.py @@ -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]: