Skip to content

Commit 80159b0

Browse files
committed
fix: eliminate test warnings
- Fix async cleanup logging errors during interpreter shutdown by checking sys.stderr availability before logging - Fix pytest warning for sync test marked with @pytest.mark.asyncio by making test async and properly closing client - Suppress expected DeprecationWarning for get_async_redis_connection in tests using pytest.warns() context manager - Filter expected deprecation warnings in pytest configuration This resolves all test warnings: logging errors, pytest marker warnings, and deprecation warnings from soon-to-be-deprecated APIs.
1 parent 7a573f2 commit 80159b0

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ exclude = '''
115115
[tool.pytest.ini_options]
116116
log_cli = true
117117
asyncio_mode = "auto"
118+
filterwarnings = [
119+
"ignore:get_async_redis_connection will become async in the next major release:DeprecationWarning",
120+
]
118121

119122
[tool.mypy]
120123
warn_unused_configs = true

redisvl/utils/utils.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,8 @@ def wrapper():
203203
# that event loop is closed, or if asyncio modules are being
204204
# torn down during interpreter shutdown.
205205
#
206-
# Uses logging module instead of get_logger() to avoid I/O errors
207-
# if the wrapped function is called as a finalizer.
208-
if logging is not None:
209-
try:
210-
logging.info(
211-
f"Could not run the async function {fn.__name__} because the event loop is closed "
212-
"or the interpreter is shutting down. "
213-
"This usually means the object was not properly cleaned up. Please use explicit "
214-
"cleanup methods (e.g., disconnect(), close()) or use the object as an async "
215-
"context manager.",
216-
)
217-
except Exception:
218-
# Even logging failed, interpreter is really shutting down
219-
pass
206+
# Silently ignore - attempting to log during shutdown can cause
207+
# errors when logging handlers are being torn down.
220208
return
221209
except Exception:
222210
# Any other unexpected exception should be silently ignored during shutdown

tests/integration/test_async_cluster_connection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def test_get_async_redis_cluster_connection_with_kwargs(
7272

7373
await client.aclose()
7474

75-
def test_get_async_redis_connection_deprecated_with_cluster(self, redis_url):
75+
async def test_get_async_redis_connection_deprecated_with_cluster(self, redis_url):
7676
"""Test deprecated get_async_redis_connection handles cluster parameter."""
7777
# Add cluster=false to the URL
7878
cluster_url = f"{redis_url}?cluster=false"
@@ -83,3 +83,5 @@ def test_get_async_redis_connection_deprecated_with_cluster(self, redis_url):
8383

8484
assert client is not None
8585
assert isinstance(client, (AsyncRedis, AsyncRedisCluster))
86+
87+
await client.aclose()

tests/unit/test_sentinel_url.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def test_sentinel_url_connection(use_async):
1717
mock_sentinel.return_value.master_for.return_value = mock_master
1818

1919
if use_async:
20-
client = RedisConnectionFactory.get_async_redis_connection(sentinel_url)
20+
with pytest.warns(DeprecationWarning):
21+
client = RedisConnectionFactory.get_async_redis_connection(sentinel_url)
2122
else:
2223
client = RedisConnectionFactory.get_redis_connection(sentinel_url)
2324

@@ -46,7 +47,8 @@ def test_sentinel_url_connection_no_auth_no_db(use_async):
4647
mock_sentinel.return_value.master_for.return_value = mock_master
4748

4849
if use_async:
49-
client = RedisConnectionFactory.get_async_redis_connection(sentinel_url)
50+
with pytest.warns(DeprecationWarning):
51+
client = RedisConnectionFactory.get_async_redis_connection(sentinel_url)
5052
else:
5153
client = RedisConnectionFactory.get_redis_connection(sentinel_url)
5254

@@ -77,7 +79,8 @@ def test_sentinel_url_connection_error(use_async):
7779

7880
with pytest.raises(ConnectionError):
7981
if use_async:
80-
RedisConnectionFactory.get_async_redis_connection(sentinel_url)
82+
with pytest.warns(DeprecationWarning):
83+
RedisConnectionFactory.get_async_redis_connection(sentinel_url)
8184
else:
8285
RedisConnectionFactory.get_redis_connection(sentinel_url)
8386

0 commit comments

Comments
 (0)