Verify that basic Redis instances created using `from_pool()` have auto_close_connection_pool set to True
(request, from_url)
| 608 | |
| 609 | @pytest.mark.parametrize("from_url", (True, False), ids=("from_url", "from_args")) |
| 610 | def 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 |
nothing calls this directly
no test coverage detected