Skip to content

Commit

Permalink
Implement cleanup of tmpdir per suggestion by @Vebop
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrondel committed Aug 9, 2024
1 parent 909e797 commit bae092b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
11 changes: 9 additions & 2 deletions tests/test_hinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sqlite3
import tempfile
from pathlib import Path
import shutil

import pytest
import yaml
Expand All @@ -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
Expand All @@ -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):
Expand Down
14 changes: 10 additions & 4 deletions tests/test_pqserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bae092b

Please sign in to comment.