Skip to content

Commit

Permalink
unit test cleanup (#165)
Browse files Browse the repository at this point in the history
## Description
Auto delete unit testing artifacts post completion.

## Additional Notes
Also making a small fix to the local_server.sh script to run the source
code in the src/ directory and not what has been installed into the
virtualenv.
  • Loading branch information
ericbuckley authored Jan 3, 2025
1 parent ecec238 commit a58652c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 4 additions & 2 deletions scripts/local_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ cd "$(dirname "$0")/.."

PORT=${1:-8000}

# Start the API server
uvicorn recordlinker.main:app --reload --reload-dir src/ --port ${PORT}
# Start the API server, reloading the server with the source code changes.
# Also specify the app directory to run the server based off the source code
# and not whats been installed into the virtual environment.
uvicorn recordlinker.main:app --app-dir src/ --reload --reload-dir src/ --port ${PORT}
16 changes: 16 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import functools
import gzip
import json
import os
import pathlib

import pytest
Expand Down Expand Up @@ -52,6 +53,21 @@ def client():
yield c


@pytest.fixture(scope="session", autouse=True)
def clean_test_database():
"""Fixture to clean up the sqlite test database file after the test suite."""
db_file = None
with database.get_test_session() as session:
# test if session is sqlite
if session.get_bind().dialect.name == "sqlite":
db_file = session.get_bind().url.database
# Yield control to the test suite
yield
# Cleanup logic: remove the database file if it exists
if db_file and os.path.exists(db_file):
os.remove(db_file)


@functools.lru_cache
@pytest.fixture
def basic_algorithm():
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/database/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This module contains the unit tests for the recordlinker.database module.
"""

import os
import unittest.mock

from recordlinker.config import settings
Expand All @@ -29,3 +29,7 @@ def test_create_sessionmaker():
assert session.bind.pool.size() == 10
assert session.bind.pool._max_overflow == 20
settings.__init__()
try:
os.remove("test.db")
except FileNotFoundError:
pass

0 comments on commit a58652c

Please sign in to comment.