Skip to content

Commit 05075cd

Browse files
committed
Tries a less invasive approach
1 parent cfbf4d6 commit 05075cd

1 file changed

Lines changed: 8 additions & 21 deletions

File tree

tests/shared/fixtures.py

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from playwright.sync_api import sync_playwright
2525
from pytest_localserver.smtp import Server as SmtpServer # type: ignore[import-untyped]
2626
from pytest_redis.factories.proc import redis_proc
27-
from redis import ConnectionPool, Redis
27+
from redis import Redis
2828
from shutil import which
2929
from sqlalchemy import create_engine, exc, text
3030
from sqlalchemy.orm.session import close_all_sessions
@@ -405,30 +405,17 @@ def browser(playwright_browser: Browser) -> Iterator[ExtendedBrowser]:
405405

406406

407407
@pytest.fixture(scope="function")
408-
def redis_pool(
409-
redis_server: RedisExecutor,
410-
monkeypatch: pytest.MonkeyPatch
411-
) -> Iterator[ConnectionPool]:
412-
408+
def redis_url(redis_server: RedisExecutor) -> Iterator[str]:
413409
import onegov.core.cache.redis as redis_cache
414-
415410
url = f'redis://{redis_server.host}:{redis_server.port}/0'
416-
pool = ConnectionPool.from_url(url)
417-
pool._redis_url = url # type: ignore[attr-defined]
418-
monkeypatch.setattr(redis_cache, 'get_pool', lambda url: pool)
419-
# only cache redis cache region per test case
420-
monkeypatch.setattr(redis_cache, 'get', lru_cache(maxsize=1024)(
421-
redis_cache.get.__wrapped__))
422-
yield pool
423-
pool.close()
424-
425-
426-
@pytest.fixture(scope="function")
427-
def redis_url(redis_pool: ConnectionPool) -> Iterator[str]:
428-
yield redis_pool._redis_url # type: ignore[attr-defined]
429-
with Redis.from_pool(redis_pool) as client:
411+
yield url
412+
with Redis.from_url(url) as client:
430413
client.flushall()
431414

415+
# clear the cached connection pools, so they can be gc'd
416+
redis_cache.get_pool.cache_clear()
417+
redis_cache.get.cache_clear()
418+
432419

433420
@pytest.fixture(scope="session")
434421
def glauth_binary() -> str:

0 commit comments

Comments
 (0)