From cd9b80f415dba8445b5bc393dd02847afb18d94a Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Mon, 27 Apr 2020 15:27:08 +0100 Subject: [PATCH] set test_errors app fixture to session scope we have one global metrics variable `metrics = GDSMetrics()`, and we then call `metrics.init_app` from within the flask application set up. The v2/test_errors.py app_for_test fixture calls create_app, would call metrics.init_app multiple times for the same metrics instance. This causes errors, so change the fixture to session level so it only calls once per test run. --- app/__init__.py | 6 +++--- tests/app/v2/test_errors.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 236a81a6c..aefc92d08 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -368,9 +368,9 @@ def setup_sqlalchemy_events(app): # this will overwrite any previous checkout_at timestamp connection_record.info['checkout_at'] = time.monotonic() - # checkin runs after the request is already torn down so we'll need to capture request info earlier. - # checkout runs when the connection is first used, ie: when we first make a query, so within the request or - # task + # checkin runs after the request is already torn down, therefore we add the request_data onto the + # connection_record as otherwise it won't have that information when checkin actually runs. + # Note: this is not a problem for checkouts as the checkout always happens within a web request or task # web requests if has_request_context(): diff --git a/tests/app/v2/test_errors.py b/tests/app/v2/test_errors.py index 1b3416bce..7c1c6b09a 100644 --- a/tests/app/v2/test_errors.py +++ b/tests/app/v2/test_errors.py @@ -3,8 +3,8 @@ from flask import url_for from sqlalchemy.exc import DataError -@pytest.fixture(scope='function') -def app_for_test(mocker): +@pytest.fixture(scope='session') +def app_for_test(): import flask from flask import Blueprint from app.authentication.auth import AuthError