Skip to content

Commit 42b5588

Browse files
authored
Improve logging of pgSTAC tests (#564)
1 parent 4a5d72f commit 42b5588

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ run_pgstac = docker-compose run --rm \
1414
-e APP_PORT=${APP_PORT} \
1515
app-pgstac
1616

17+
LOG_LEVEL ?= warning
18+
1719
.PHONY: image
1820
image:
1921
docker-compose build
@@ -44,15 +46,15 @@ docker-shell-pgstac:
4446

4547
.PHONY: test-sqlalchemy
4648
test-sqlalchemy: run-joplin-sqlalchemy
47-
$(run_sqlalchemy) /bin/bash -c 'export && ./scripts/wait-for-it.sh database:5432 && cd /app/stac_fastapi/sqlalchemy/tests/ && pytest -vvv'
49+
$(run_sqlalchemy) /bin/bash -c 'export && ./scripts/wait-for-it.sh database:5432 && cd /app/stac_fastapi/sqlalchemy/tests/ && pytest -vvv --log-cli-level $(LOG_LEVEL)'
4850

4951
.PHONY: test-pgstac
5052
test-pgstac:
51-
$(run_pgstac) /bin/bash -c 'export && ./scripts/wait-for-it.sh database:5432 && cd /app/stac_fastapi/pgstac/tests/ && pytest -vvv'
53+
$(run_pgstac) /bin/bash -c 'export && ./scripts/wait-for-it.sh database:5432 && cd /app/stac_fastapi/pgstac/tests/ && pytest -vvv --log-cli-level $(LOG_LEVEL)'
5254

5355
.PHONY: test-api
5456
test-api:
55-
$(run_sqlalchemy) /bin/bash -c 'cd /app/stac_fastapi/api && pytest -svvv'
57+
$(run_sqlalchemy) /bin/bash -c 'cd /app/stac_fastapi/api && pytest -svvv --log-cli-level $(LOG_LEVEL)'
5658

5759
.PHONY: run-database
5860
run-database:

stac_fastapi/pgstac/tests/conftest.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import json
3+
import logging
34
import os
45
import time
56
from typing import Callable, Dict
@@ -33,6 +34,8 @@
3334
from stac_fastapi.pgstac.transactions import BulkTransactionsClient, TransactionsClient
3435
from stac_fastapi.pgstac.types.search import PgstacSearch
3536

37+
logger = logging.getLogger(__name__)
38+
3639
DATA_DIR = os.path.join(os.path.dirname(__file__), "data")
3740

3841
settings = Settings(testing=True)
@@ -46,7 +49,7 @@ def event_loop():
4649

4750
@pytest.fixture(scope="session")
4851
async def pg():
49-
print(f"Connecting to write database {settings.writer_connection_string}")
52+
logger.info(f"Connecting to write database {settings.writer_connection_string}")
5053
os.environ["orig_postgres_dbname"] = settings.postgres_dbname
5154
conn = await asyncpg.connect(dsn=settings.writer_connection_string)
5255
try:
@@ -64,21 +67,20 @@ async def pg():
6467
"ALTER DATABASE pgstactestdb SET search_path to pgstac, public;"
6568
)
6669
await conn.close()
67-
print("migrating...")
70+
logger.info("migrating...")
6871
os.environ["postgres_dbname"] = "pgstactestdb"
6972
conn = await asyncpg.connect(dsn=settings.testing_connection_string)
70-
val = await conn.fetchval("SELECT true")
71-
print(val)
73+
await conn.execute("SELECT true")
7274
await conn.close()
7375
db = PgstacDB(dsn=settings.testing_connection_string)
7476
migrator = Migrate(db)
7577
version = migrator.run_migration()
7678
db.close()
77-
print(f"PGStac Migrated to {version}")
79+
logger.info(f"PGStac Migrated to {version}")
7880

7981
yield settings.testing_connection_string
8082

81-
print("Getting rid of test database")
83+
logger.info("Getting rid of test database")
8284
os.environ["postgres_dbname"] = os.environ["orig_postgres_dbname"]
8385
conn = await asyncpg.connect(dsn=settings.writer_connection_string)
8486
try:
@@ -94,9 +96,9 @@ async def pg():
9496

9597
@pytest.fixture(autouse=True)
9698
async def pgstac(pg):
97-
print(f"{os.environ['postgres_dbname']}")
99+
logger.info(f"{os.environ['postgres_dbname']}")
98100
yield
99-
print("Truncating Data")
101+
logger.info("Truncating Data")
100102
conn = await asyncpg.connect(dsn=settings.testing_connection_string)
101103
await conn.execute(
102104
"""
@@ -107,7 +109,7 @@ async def pgstac(pg):
107109
with PgstacDB(dsn=settings.testing_connection_string) as db:
108110
migrator = Migrate(db)
109111
version = migrator.run_migration()
110-
print(f"PGStac Migrated to {version}")
112+
logger.info(f"PGStac Migrated to {version}")
111113

112114

113115
# Run all the tests that use the api_client in both db hydrate and api hydrate mode
@@ -126,7 +128,7 @@ def api_client(request, pg):
126128
api_settings.openapi_url = prefix + api_settings.openapi_url
127129
api_settings.docs_url = prefix + api_settings.docs_url
128130

129-
print(
131+
logger.info(
130132
"creating client with settings, hydrate: {}, router prefix: '{}'".format(
131133
api_settings.use_api_hydrate, prefix
132134
)
@@ -159,7 +161,7 @@ def api_client(request, pg):
159161

160162
@pytest.fixture(scope="function")
161163
async def app(api_client):
162-
print("Creating app Fixture")
164+
logger.info("Creating app Fixture")
163165
time.time()
164166
app = api_client.app
165167
await connect_to_db(app)
@@ -168,12 +170,12 @@ async def app(api_client):
168170

169171
await close_db_connection(app)
170172

171-
print("Closed Pools.")
173+
logger.info("Closed Pools.")
172174

173175

174176
@pytest.fixture(scope="function")
175177
async def app_client(app):
176-
print("creating app_client")
178+
logger.info("creating app_client")
177179

178180
base_url = "http://test"
179181
if app.state.router_prefix != "":

0 commit comments

Comments
 (0)