Skip to content

Commit 7f81c5c

Browse files
alukachgadomski
authored andcommitted
fix, tests: quiet things down a bit
Ported from stac-utils/stac-fastapi@f3835e6
1 parent 943f86e commit 7f81c5c

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
APP_HOST ?= 0.0.0.0
33
APP_PORT ?= 8080
44
EXTERNAL_APP_PORT ?= ${APP_PORT}
5+
LOG_LEVEL ?= warning
56

67
run = docker-compose run --rm \
78
-p ${EXTERNAL_APP_PORT}:${APP_PORT} \
@@ -27,7 +28,7 @@ docker-shell:
2728

2829
.PHONY: test
2930
test:
30-
$(run) /bin/bash -c 'export && ./scripts/wait-for-it.sh database:5432 && cd /app/tests/ && pytest -vvv'
31+
$(run) /bin/bash -c 'export && ./scripts/wait-for-it.sh database:5432 && cd /app/tests/ && pytest -vvv --log-cli-level $(LOG_LEVEL)'
3132

3233
.PHONY: run-database
3334
run-database:

tests/conftest.py

Lines changed: 13 additions & 11 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
@@ -38,6 +39,8 @@
3839
settings = Settings(testing=True)
3940
pgstac_api_hydrate_settings = Settings(testing=True, use_api_hydrate=True)
4041

42+
logger = logging.getLogger(__name__)
43+
4144

4245
@pytest.fixture(scope="session")
4346
def event_loop():
@@ -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,17 +67,16 @@ 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

@@ -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
"""
@@ -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)