Skip to content

Commit f59c38c

Browse files
BYKclaude
andcommitted
fix: Fix test assertions for warnings.warn and missing decorators
- Update test_close_with_async_transport_warns and test_flush_with_async_transport_warns to check warnings.warn instead of logger.warning - Add missing @skip_under_gevent, @pytest.mark.asyncio, and @pytest.mark.skipif decorators on test_async_transport_concurrent_requests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9b0a712 commit f59c38c

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

tests/test_client.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,11 +1655,9 @@ async def test_async_proxy(monkeypatch, testcase):
16551655
@skip_under_gevent
16561656
@pytest.mark.asyncio
16571657
@pytest.mark.skipif(not PY38, reason="Async client methods require Python 3.8+")
1658-
async def test_close_with_async_transport_warns(caplog):
1659-
"""Test close() with AsyncHttpTransport logs a warning."""
1660-
import logging
1661-
1662-
caplog.set_level(logging.WARNING)
1658+
async def test_close_with_async_transport_warns():
1659+
"""Test close() with AsyncHttpTransport emits a warning."""
1660+
import warnings as _warnings
16631661

16641662
client = Client(
16651663
"https://foo@sentry.io/123",
@@ -1668,13 +1666,10 @@ async def test_close_with_async_transport_warns(caplog):
16681666
)
16691667
assert isinstance(client.transport, AsyncHttpTransport)
16701668

1671-
with mock.patch("sentry_sdk.client.logger") as mock_logger:
1669+
with _warnings.catch_warnings(record=True) as w:
1670+
_warnings.simplefilter("always")
16721671
client.close()
1673-
mock_logger.warning.assert_called_with(
1674-
"close() used with AsyncHttpTransport. "
1675-
"Prefer close_async() for graceful async shutdown. "
1676-
"Performing synchronous best-effort cleanup."
1677-
)
1672+
assert any("close_async()" in str(warning.message) for warning in w)
16781673

16791674

16801675
@skip_under_gevent
@@ -1726,19 +1721,20 @@ async def test_close_async_no_transport():
17261721
@pytest.mark.asyncio
17271722
@pytest.mark.skipif(not PY38, reason="Async client methods require Python 3.8+")
17281723
async def test_flush_with_async_transport_warns():
1729-
"""Test flush() with AsyncHttpTransport logs a warning and returns."""
1724+
"""Test flush() with AsyncHttpTransport emits a warning and returns."""
1725+
import warnings as _warnings
1726+
17301727
client = Client(
17311728
"https://foo@sentry.io/123",
17321729
_experiments={"transport_async": True},
17331730
integrations=[AsyncioIntegration()],
17341731
)
17351732
assert isinstance(client.transport, AsyncHttpTransport)
17361733

1737-
with mock.patch("sentry_sdk.client.logger") as mock_logger:
1734+
with _warnings.catch_warnings(record=True) as w:
1735+
_warnings.simplefilter("always")
17381736
client.flush(timeout=1.0)
1739-
mock_logger.warning.assert_called_with(
1740-
"flush() used with AsyncHttpTransport. Please use flush_async() instead."
1741-
)
1737+
assert any("flush_async()" in str(warning.message) for warning in w)
17421738
await client.close_async()
17431739

17441740

tests/test_transport.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,9 @@ async def test_async_two_way_ssl_authentication():
10551055
await client.close_async()
10561056

10571057

1058+
@skip_under_gevent
1059+
@pytest.mark.asyncio
1060+
@pytest.mark.skipif(not PY38, reason="Async transport requires Python 3.8+")
10581061
async def test_async_transport_concurrent_requests(
10591062
capturing_server, make_client, caplog
10601063
):

0 commit comments

Comments
 (0)