|
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 Redis |
| 27 | +from redis import ConnectionPool, 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 |
@@ -404,17 +404,28 @@ def browser(playwright_browser: Browser) -> Iterator[ExtendedBrowser]: |
404 | 404 | context.close() |
405 | 405 |
|
406 | 406 |
|
| 407 | +@pytest.fixture(scope="session") |
| 408 | +def redis_url_session(redis_server: RedisExecutor) -> str: |
| 409 | + return f'redis://{redis_server.host}:{redis_server.port}/0' |
| 410 | + |
| 411 | +@pytest.fixture(scope="session") |
| 412 | +def redis_pool( |
| 413 | + redis_url_session: str, |
| 414 | + monkeysession: pytest.MonkeyPatch |
| 415 | +) -> Iterator[ConnectionPool]: |
| 416 | + pool = ConnectionPool.from_url(redis_url_session, socket_keepalive=False) |
| 417 | + monkeysession.setattr('onegov.core.cache.redis.get_pool', lambda url: pool) |
| 418 | + yield pool |
| 419 | + pool.close() |
| 420 | + |
| 421 | + |
407 | 422 | @pytest.fixture(scope="function") |
408 | | -def redis_url(redis_server: RedisExecutor) -> Iterator[str]: |
409 | | - url = f'redis://{redis_server.host}:{redis_server.port}/0' |
410 | | - yield url |
411 | | - # disable any potentially resource hungry options and make sure |
412 | | - # we clean up our connection after we're done |
413 | | - with Redis.from_url( |
414 | | - url, |
415 | | - socket_keepalive=False, |
416 | | - single_connection_client=True, |
417 | | - ) as client: |
| 423 | +def redis_url( |
| 424 | + redis_url_session: str, |
| 425 | + redis_pool: ConnectionPool |
| 426 | +) -> Iterator[str]: |
| 427 | + yield redis_url_session |
| 428 | + with Redis(connection_pool=redis_pool) as client: |
418 | 429 | client.flushall() |
419 | 430 |
|
420 | 431 |
|
|
0 commit comments