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.
This commit is contained in:
Leo Hemsted
2020-04-27 15:27:08 +01:00
committed by David McDonald
parent faa8faa0c4
commit cd9b80f415
2 changed files with 5 additions and 5 deletions

View File

@@ -368,9 +368,9 @@ def setup_sqlalchemy_events(app):
# this will overwrite any previous checkout_at timestamp # this will overwrite any previous checkout_at timestamp
connection_record.info['checkout_at'] = time.monotonic() 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. # checkin runs after the request is already torn down, therefore we add the request_data onto the
# checkout runs when the connection is first used, ie: when we first make a query, so within the request or # connection_record as otherwise it won't have that information when checkin actually runs.
# task # Note: this is not a problem for checkouts as the checkout always happens within a web request or task
# web requests # web requests
if has_request_context(): if has_request_context():

View File

@@ -3,8 +3,8 @@ from flask import url_for
from sqlalchemy.exc import DataError from sqlalchemy.exc import DataError
@pytest.fixture(scope='function') @pytest.fixture(scope='session')
def app_for_test(mocker): def app_for_test():
import flask import flask
from flask import Blueprint from flask import Blueprint
from app.authentication.auth import AuthError from app.authentication.auth import AuthError