From c3398362dbc9a50999ce00a581ef3476f6595797 Mon Sep 17 00:00:00 2001 From: Jaromir Wysoglad Date: Thu, 26 Feb 2026 23:03:27 +0000 Subject: [PATCH] Fix tests with gabbi 4.x Based on a similar fix in placement: https://review.opendev.org/c/openstack/placement/+/972708 Story: 2011683 Task: 53888 Change-Id: Idbb79ffd7e304837ee943aa58dd0121422cab182 Signed-off-by: Jaromir Wysoglad --- cloudkitty/tests/gabbi/fixtures.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cloudkitty/tests/gabbi/fixtures.py b/cloudkitty/tests/gabbi/fixtures.py index 9f0c135e..52ddda17 100644 --- a/cloudkitty/tests/gabbi/fixtures.py +++ b/cloudkitty/tests/gabbi/fixtures.py @@ -516,6 +516,23 @@ class UTCFixture(fixture.GabbiFixture): self._tzmock.stop() +# NOTE(stephenfin): Since gabbi 4.x, the intercept function (setup_app) is +# called during test construction, before fixtures are started, so CONF is None +# at that point. This lazy wrapper defers actual app creation until the first +# request, by which time the fixtures will have been started and CONF will be +# set. +class LazyWSGIApp: + """A lazy WSGI app wrapper that defers app creation until first request.""" + + def __init__(self): + self._app = None + + def __call__(self, environ, start_response): + if self._app is None: + self._app = app.load_app() + return self._app(environ, start_response) + + def setup_app(): messaging.setup() # FIXME(sheeprine): Extension fixtures are interacting with transformers @@ -524,4 +541,4 @@ def setup_app(): 'cloudkitty.collector.get_collector', return_value=None) with no_collector: - return app.load_app() + return LazyWSGIApp()