From de15c77160a4e914c69e7f8c0adb4b416521bf1d Mon Sep 17 00:00:00 2001 From: Eric Fahlgren Date: Wed, 23 Oct 2024 09:18:34 -0700 Subject: [PATCH] tests: fix spurious failure of stats tests Some of the test_stats tests would fail occasionally with the wrong queue length. Traced it back to the redis 'Queue' object somehow persisting across tests. We now ensure that a fresh queue is used for each test. Signed-off-by: Eric Fahlgren --- tests/conftest.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index df67cc34..015ca8e3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,6 +4,7 @@ import pytest from fakeredis import FakeStrictRedis +from rq import Queue from fastapi.testclient import TestClient from asu.config import settings @@ -93,12 +94,16 @@ def app(redis_server, test_path, monkeypatch): def mocked_redis_client(*args, **kwargs): return redis_server + def mocked_redis_queue(): + return Queue(connection=redis_server, is_async=settings.async_queue) + settings.public_path = Path(test_path) / "public" settings.async_queue = False for branch in "1.2", "19.07", "21.02": if branch not in settings.branches: settings.branches[branch] = {"path": "releases/{version}"} + monkeypatch.setattr("asu.util.get_queue", mocked_redis_queue) monkeypatch.setattr("asu.util.get_redis_client", mocked_redis_client) monkeypatch.setattr("asu.routers.api.get_redis_client", mocked_redis_client)