summaryrefslogtreecommitdiff
path: root/tests/conftest.py
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2020-08-19 10:46:02 -0700
committerAndy McCurdy <andy@andymccurdy.com>2020-08-19 10:46:02 -0700
commitb80d423cc531c5db972d35ba72424cf9cf8772ff (patch)
treed1af550e0d749fa3f53d31b03dd5e84e0537108e /tests/conftest.py
parentf9ab1d35f8ec633a25c223ed979cef34a68072fe (diff)
downloadredis-py-b80d423cc531c5db972d35ba72424cf9cf8772ff.tar.gz
Added the ACL LOG command available in Redis 6
`acl_log()` returns a list of dictionaries, each describing a log entry. `acl_log_reset()` instructs the server to truncate the log. Thanks @2014BDuck Fixes #1307
Diffstat (limited to 'tests/conftest.py')
-rw-r--r--tests/conftest.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 26893db..cd4d489 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -2,6 +2,7 @@ import pytest
import random
import redis
from distutils.version import StrictVersion
+from redis.connection import parse_url
from unittest.mock import Mock
from urllib.parse import urlparse
@@ -60,19 +61,31 @@ def skip_unless_arch_bits(arch_bits):
reason="server is not {}-bit".format(arch_bits))
-def _get_client(cls, request, single_connection_client=True, **kwargs):
+def _get_client(cls, request, single_connection_client=True, flushdb=True,
+ **kwargs):
+ """
+ Helper for fixtures or tests that need a Redis client
+
+ Uses the "--redis-url" command line argument for connection info. Unlike
+ ConnectionPool.from_url, keyword arguments to this function override
+ values specified in the URL.
+ """
redis_url = request.config.getoption("--redis-url")
- client = cls.from_url(redis_url, **kwargs)
+ url_options = parse_url(redis_url)
+ url_options.update(kwargs)
+ pool = redis.ConnectionPool(**url_options)
+ client = cls(connection_pool=pool)
if single_connection_client:
client = client.client()
if request:
def teardown():
- try:
- client.flushdb()
- except redis.ConnectionError:
- # handle cases where a test disconnected a client
- # just manually retry the flushdb
- client.flushdb()
+ if flushdb:
+ try:
+ client.flushdb()
+ except redis.ConnectionError:
+ # handle cases where a test disconnected a client
+ # just manually retry the flushdb
+ client.flushdb()
client.close()
client.connection_pool.disconnect()
request.addfinalizer(teardown)