From bae092ba81a622fff0ace22acdd6b309940a046d Mon Sep 17 00:00:00 2001 From: Brian Brondel Date: Fri, 9 Aug 2024 10:03:01 -0700 Subject: [PATCH] Implement cleanup of tmpdir per suggestion by @vebop --- tests/test_hinfo.py | 11 +++++++++-- tests/test_pqserver.py | 14 ++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/tests/test_hinfo.py b/tests/test_hinfo.py index c68edad6..df28da23 100644 --- a/tests/test_hinfo.py +++ b/tests/test_hinfo.py @@ -2,6 +2,7 @@ import sqlite3 import tempfile from pathlib import Path +import shutil import pytest import yaml @@ -14,7 +15,10 @@ def tmpdir(scope="module"): os.environ["INSTRUMENT"] = "LATISS" tmpdir = Path(tempfile.mkdtemp()) - return tmpdir + try: + yield tmpdir + finally: + shutil.rmtree(tmpdir) @pytest.fixture @@ -38,7 +42,10 @@ def engine(tmpdir, scope="module"): hinfo.engine = utils.setup_postgres() hinfo.instrument = "LATISS" - return hinfo.engine + try: + yield hinfo.engine + finally: + hinfo.engine.dispose() def _header_lookup(header, key): diff --git a/tests/test_pqserver.py b/tests/test_pqserver.py index 95289b5a..c7bde590 100644 --- a/tests/test_pqserver.py +++ b/tests/test_pqserver.py @@ -16,8 +16,10 @@ def _assert_http_status(response: Response, status: int): @pytest.fixture def tmpdir(scope="module"): tmpdir = Path(tempfile.mkdtemp()) - return tmpdir - shutil.rmtree(tmpdir) + try: + yield tmpdir + finally: + shutil.rmtree(tmpdir) @pytest.fixture @@ -53,9 +55,13 @@ def db(tmpdir, scope="module"): @pytest.fixture def app(db, scope="module"): os.environ["POSTGRES_URL"] = f"sqlite:///{db}" - from lsst.consdb import pqserver + from lsst.consdb import pqserver, utils - return pqserver.app + pqserver.engine = utils.setup_postgres() + try: + yield pqserver.app + finally: + pqserver.engine.dispose() @pytest.fixture