MCPcopy
hub / github.com/redis/redis-py / test_redis_from_pool

Function test_redis_from_pool

tests/test_connection.py:610–639  ·  view source on GitHub ↗

Verify that basic Redis instances created using `from_pool()` have auto_close_connection_pool set to True

(request, from_url)

Source from the content-addressed store, hash-verified

608
609@pytest.mark.parametrize("from_url", (True, False), ids=("from_url", "from_args"))
610def test_redis_from_pool(request, from_url):
611 """Verify that basic Redis instances created using `from_pool()`
612 have auto_close_connection_pool set to True"""
613
614 url: str = request.config.getoption("--redis-url")
615 url_args = parse_url(url)
616
617 pool = None
618
619 def get_redis_connection():
620 nonlocal pool
621 if from_url:
622 pool = ConnectionPool.from_url(url)
623 else:
624 pool = ConnectionPool(**url_args)
625 return Redis.from_pool(pool)
626
627 called = 0
628
629 def mock_disconnect(target_pool):
630 nonlocal called
631 if pool is not None and target_pool is pool:
632 called += 1
633
634 with patch.object(ConnectionPool, "disconnect", mock_disconnect):
635 with get_redis_connection() as r1:
636 assert r1.auto_close_connection_pool is True
637
638 assert called == 1
639 pool.disconnect()
640
641
642@pytest.mark.fixed_client

Callers

nothing calls this directly

Calls 4

disconnectMethod · 0.95
parse_urlFunction · 0.90
objectMethod · 0.80
get_redis_connectionFunction · 0.70

Tested by

no test coverage detected