diff --git a/docker-compose.yml b/docker-compose.yml index 7804f09c8a..60657d5653 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -103,7 +103,7 @@ services: - all redis-stack: - image: ${REDIS_STACK_IMAGE:-redis/redis-stack-server:edge} + image: ${REDIS_STACK_IMAGE:-redis/redis-stack-server:latest} container_name: redis-stack ports: - 6479:6379 @@ -112,6 +112,7 @@ services: profiles: - standalone - all-stack + - all redis-stack-graph: image: redis/redis-stack-server:6.2.6-v15 diff --git a/tests/test_asyncio/test_connection.py b/tests/test_asyncio/test_connection.py index e584fc6999..d4956f16e9 100644 --- a/tests/test_asyncio/test_connection.py +++ b/tests/test_asyncio/test_connection.py @@ -1,6 +1,7 @@ import asyncio import socket import types +from errno import ECONNREFUSED from unittest.mock import patch import pytest @@ -36,15 +37,16 @@ async def test_invalid_response(create_redis): fake_stream = MockStream(raw + b"\r\n") parser: _AsyncRESPBase = r.connection._parser - with mock.patch.object(parser, "_stream", fake_stream): - with pytest.raises(InvalidResponse) as cm: - await parser.read_response() + if isinstance(parser, _AsyncRESPBase): - assert str(cm.value) == f"Protocol Error: {raw!r}" + exp_err = f"Protocol Error: {raw!r}" else: - assert ( - str(cm.value) == f'Protocol error, got "{raw.decode()}" as reply type byte' - ) + exp_err = f'Protocol error, got "{raw.decode()}" as reply type byte' + + with mock.patch.object(parser, "_stream", fake_stream): + with pytest.raises(InvalidResponse, match=exp_err): + await parser.read_response() + await r.connection.disconnect() @@ -170,10 +172,9 @@ async def test_connect_timeout_error_without_retry(): conn._connect = mock.AsyncMock() conn._connect.side_effect = socket.timeout - with pytest.raises(TimeoutError) as e: + with pytest.raises(TimeoutError, match="Timeout connecting to server"): await conn.connect() assert conn._connect.call_count == 1 - assert str(e.value) == "Timeout connecting to server" @pytest.mark.onlynoncluster @@ -531,17 +532,14 @@ async def test_format_error_message(conn, error, expected_message): async def test_network_connection_failure(): - with pytest.raises(ConnectionError) as e: + exp_err = rf"^Error {ECONNREFUSED} connecting to 127.0.0.1:9999.(.+)$" + with pytest.raises(ConnectionError, match=exp_err): redis = Redis(host="127.0.0.1", port=9999) await redis.set("a", "b") - assert str(e.value).startswith("Error 111 connecting to 127.0.0.1:9999. Connect") async def test_unix_socket_connection_failure(): - with pytest.raises(ConnectionError) as e: + exp_err = "Error 2 connecting to unix:///tmp/a.sock. No such file or directory." + with pytest.raises(ConnectionError, match=exp_err): redis = Redis(unix_socket_path="unix:///tmp/a.sock") await redis.set("a", "b") - assert ( - str(e.value) - == "Error 2 connecting to unix:///tmp/a.sock. No such file or directory." - ) diff --git a/tests/test_connection.py b/tests/test_connection.py index fbc23ae8c0..6c1498a329 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -4,6 +4,7 @@ import sys import threading import types +from errno import ECONNREFUSED from typing import Any from unittest import mock from unittest.mock import call, patch @@ -44,9 +45,8 @@ def test_invalid_response(r): raw = b"x" parser = r.connection._parser with mock.patch.object(parser._buffer, "readline", return_value=raw): - with pytest.raises(InvalidResponse) as cm: + with pytest.raises(InvalidResponse, match=f"Protocol Error: {raw!r}"): parser.read_response() - assert str(cm.value) == f"Protocol Error: {raw!r}" @skip_if_server_version_lt("4.0.0") @@ -141,10 +141,9 @@ def test_connect_timeout_error_without_retry(self): conn._connect = mock.Mock() conn._connect.side_effect = socket.timeout - with pytest.raises(TimeoutError) as e: + with pytest.raises(TimeoutError, match="Timeout connecting to server"): conn.connect() assert conn._connect.call_count == 1 - assert str(e.value) == "Timeout connecting to server" self.clear(conn) @@ -349,20 +348,17 @@ def test_format_error_message(conn, error, expected_message): def test_network_connection_failure(): - with pytest.raises(ConnectionError) as e: + exp_err = f"Error {ECONNREFUSED} connecting to localhost:9999. Connection refused." + with pytest.raises(ConnectionError, match=exp_err): redis = Redis(port=9999) redis.set("a", "b") - assert str(e.value) == "Error 111 connecting to localhost:9999. Connection refused." def test_unix_socket_connection_failure(): - with pytest.raises(ConnectionError) as e: + exp_err = "Error 2 connecting to unix:///tmp/a.sock. No such file or directory." + with pytest.raises(ConnectionError, match=exp_err): redis = Redis(unix_socket_path="unix:///tmp/a.sock") redis.set("a", "b") - assert ( - str(e.value) - == "Error 2 connecting to unix:///tmp/a.sock. No such file or directory." - ) class TestUnitConnectionPool: diff --git a/tests/test_multiprocessing.py b/tests/test_multiprocessing.py index 5cda3190a6..116d20dab0 100644 --- a/tests/test_multiprocessing.py +++ b/tests/test_multiprocessing.py @@ -1,5 +1,6 @@ import contextlib import multiprocessing +import sys import pytest import redis @@ -8,6 +9,9 @@ from .conftest import _get_client +if sys.platform == "darwin": + multiprocessing.set_start_method("fork", force=True) + @contextlib.contextmanager def exit_callback(callback, *args):