From 0c68df3d5840a769b62def2f4f4f44d566592e93 Mon Sep 17 00:00:00 2001 From: Vytautas Liuolia Date: Sat, 12 Aug 2023 00:23:22 +0200 Subject: [PATCH] fix(asgilook): ensure that no FakeRedis state persists between tests (#2168) --- examples/asgilook/tests/conftest.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/asgilook/tests/conftest.py b/examples/asgilook/tests/conftest.py index 565bb970c..420a256df 100644 --- a/examples/asgilook/tests/conftest.py +++ b/examples/asgilook/tests/conftest.py @@ -38,8 +38,15 @@ def storage_path(tmpdir_factory): @pytest.fixture def client(predictable_uuid, storage_path): + # NOTE(vytas): Unlike the sync FakeRedis, fakeredis.aioredis.FakeRedis + # seems to share a global state in 2.17.0 (by design or oversight). + # Make sure we initialize a new fake server for every test case. + def fake_redis_from_url(*args, **kwargs): + server = fakeredis.FakeServer() + return fakeredis.aioredis.FakeRedis(server=server) + config = Config() - config.redis_from_url = fakeredis.aioredis.FakeRedis.from_url + config.redis_from_url = fake_redis_from_url config.redis_host = 'redis://localhost' config.storage_path = storage_path config.uuid_generator = predictable_uuid