Skip to content

Commit

Permalink
Moves query logger duration into pytest.ini file
Browse files Browse the repository at this point in the history
  • Loading branch information
mouse-reeve committed Aug 9, 2024
1 parent cc72507 commit 26b6699
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bookwyrm/tests/query_logger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
""" Log query runtimes for testing """
import time
from environs import Env

env = Env()
env.read_env()
MAX_QUERY_DURATION = float(env("MAX_QUERY_DURATION"))


class QueryLogger:
Expand Down Expand Up @@ -30,7 +35,7 @@ def __call__(self, execute, sql, params, many, context):
self.queries.append(current_query)


def raise_long_query_runtime(queries, threshold=0.0006):
def raise_long_query_runtime(queries, threshold=MAX_QUERY_DURATION):
"""Raises an exception if any query took longer than the threshold"""
for query in queries:
if query["duration"] > threshold:
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ env =
EMAIL_HOST_PASSWORD =
EMAIL_USE_TLS = true
ENABLE_PREVIEW_IMAGES = false
MAX_QUERY_DURATION = 0.005

0 comments on commit 26b6699

Please sign in to comment.