|
24 | 24 | from playwright.sync_api import sync_playwright |
25 | 25 | from pytest_localserver.smtp import Server as SmtpServer # type: ignore[import-untyped] |
26 | 26 | from pytest_redis.factories.proc import redis_proc |
27 | | -from redis import ConnectionPool, Redis |
| 27 | +from redis import Redis |
28 | 28 | from shutil import which |
29 | 29 | from sqlalchemy import create_engine, exc, text |
30 | 30 | from sqlalchemy.orm.session import close_all_sessions |
@@ -405,30 +405,17 @@ def browser(playwright_browser: Browser) -> Iterator[ExtendedBrowser]: |
405 | 405 |
|
406 | 406 |
|
407 | 407 | @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]: |
413 | 409 | import onegov.core.cache.redis as redis_cache |
414 | | - |
415 | 410 | 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: |
430 | 413 | client.flushall() |
431 | 414 |
|
| 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 | + |
432 | 419 |
|
433 | 420 | @pytest.fixture(scope="session") |
434 | 421 | def glauth_binary() -> str: |
|
0 commit comments