From cf64d0cf381decfc8b03bd4aa10bb88f37c25044 Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Thu, 30 Jan 2025 11:28:56 -0800 Subject: [PATCH 1/6] fix(ci): Various errors on master --- sentry_sdk/_queue.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sentry_sdk/_queue.py b/sentry_sdk/_queue.py index c0410d1f92..a21c86ec0a 100644 --- a/sentry_sdk/_queue.py +++ b/sentry_sdk/_queue.py @@ -86,11 +86,13 @@ class EmptyError(Exception): "Exception raised by Queue.get(block=0)/get_nowait()." + pass class FullError(Exception): "Exception raised by Queue.put(block=0)/put_nowait()." + pass From b102cec16c9c1323373f7c824b708c684b70d9cf Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Thu, 30 Jan 2025 15:41:46 -0800 Subject: [PATCH 2/6] fix pymongo tests --- tests/integrations/pymongo/test_pymongo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrations/pymongo/test_pymongo.py b/tests/integrations/pymongo/test_pymongo.py index 80fe40fdcf..10f1c9fba9 100644 --- a/tests/integrations/pymongo/test_pymongo.py +++ b/tests/integrations/pymongo/test_pymongo.py @@ -10,7 +10,7 @@ @pytest.fixture(scope="session") def mongo_server(): server = MockupDB(verbose=True) - server.autoresponds("ismaster", maxWireVersion=6) + server.autoresponds("ismaster", maxWireVersion=7) server.run() server.autoresponds( {"find": "test_collection"}, cursor={"id": 123, "firstBatch": []} From 08c96bab771b014969cdaf26d5affeec8c184c00 Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Thu, 30 Jan 2025 15:41:57 -0800 Subject: [PATCH 3/6] fix huggingface hub tests --- .../huggingface_hub/test_huggingface_hub.py | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tests/integrations/huggingface_hub/test_huggingface_hub.py b/tests/integrations/huggingface_hub/test_huggingface_hub.py index f43159d80e..e017ce2449 100644 --- a/tests/integrations/huggingface_hub/test_huggingface_hub.py +++ b/tests/integrations/huggingface_hub/test_huggingface_hub.py @@ -12,6 +12,13 @@ from unittest import mock # python 3.3 and above +def mock_client_post(client, post_mock): + # huggingface-hub==0.28.0 deprecates the `post` method + # so patch `_inner_post` instead + client.post = post_mock + client._inner_post = post_mock + + @pytest.mark.parametrize( "send_default_pii, include_prompts, details_arg", itertools.product([True, False], repeat=3), @@ -28,7 +35,7 @@ def test_nonstreaming_chat_completion( client = InferenceClient("some-model") if details_arg: - client.post = mock.Mock( + post_mock = mock.Mock( return_value=b"""[{ "generated_text": "the model response", "details": { @@ -40,9 +47,11 @@ def test_nonstreaming_chat_completion( }]""" ) else: - client.post = mock.Mock( + post_mock = mock.Mock( return_value=b'[{"generated_text": "the model response"}]' ) + mock_client_post(client, post_mock) + with start_transaction(name="huggingface_hub tx"): response = client.text_generation( prompt="hello", @@ -84,7 +93,8 @@ def test_streaming_chat_completion( events = capture_events() client = InferenceClient("some-model") - client.post = mock.Mock( + + post_mock = mock.Mock( return_value=[ b"""data:{ "token":{"id":1, "special": false, "text": "the model "} @@ -95,6 +105,8 @@ def test_streaming_chat_completion( }""", ] ) + mock_client_post(client, post_mock) + with start_transaction(name="huggingface_hub tx"): response = list( client.text_generation( @@ -131,7 +143,9 @@ def test_bad_chat_completion(sentry_init, capture_events): events = capture_events() client = InferenceClient("some-model") - client.post = mock.Mock(side_effect=OverloadedError("The server is overloaded")) + post_mock = mock.Mock(side_effect=OverloadedError("The server is overloaded")) + mock_client_post(client, post_mock) + with pytest.raises(OverloadedError): client.text_generation(prompt="hello") @@ -147,13 +161,15 @@ def test_span_origin(sentry_init, capture_events): events = capture_events() client = InferenceClient("some-model") - client.post = mock.Mock( + post_mock = mock.Mock( return_value=[ b"""data:{ "token":{"id":1, "special": false, "text": "the model "} }""", ] ) + mock_client_post(client, post_mock) + with start_transaction(name="huggingface_hub tx"): list( client.text_generation( From 2e480c99131b31ae53c75757c9b92005be490b04 Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Thu, 30 Jan 2025 15:42:07 -0800 Subject: [PATCH 4/6] fix aiohttp tests --- tests/integrations/aiohttp/test_aiohttp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index cd65e7cdd5..ecca8f6834 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -475,7 +475,7 @@ async def hello(request): @pytest.mark.asyncio async def test_crumb_capture( - sentry_init, aiohttp_raw_server, aiohttp_client, loop, capture_events + sentry_init, aiohttp_raw_server, aiohttp_client, event_loop, capture_events ): def before_breadcrumb(crumb, hint): crumb["data"]["extra"] = "foo" From 0edb5a007fce7071a4afa099a5c9410a5a935a8c Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Thu, 30 Jan 2025 15:53:40 -0800 Subject: [PATCH 5/6] fix aiohttp tests again --- tests/integrations/aiohttp/test_aiohttp.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index ecca8f6834..1a2b39c978 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -1,5 +1,6 @@ import asyncio import json +import sys from contextlib import suppress from unittest import mock @@ -473,9 +474,22 @@ async def hello(request): assert error_event["contexts"]["trace"]["trace_id"] == trace_id +if sys.version_info >= (3, 12): + + @pytest.fixture + def asyncio_loop(event_loop): + yield event_loop + +else: + + @pytest.fixture + def asyncio_loop(loop): + yield loop + + @pytest.mark.asyncio async def test_crumb_capture( - sentry_init, aiohttp_raw_server, aiohttp_client, event_loop, capture_events + sentry_init, aiohttp_raw_server, aiohttp_client, asyncio_loop, capture_events ): def before_breadcrumb(crumb, hint): crumb["data"]["extra"] = "foo" From 7558b2fc5fb1b655dd958fa3ce043cfd4a9cc0fb Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Thu, 30 Jan 2025 16:18:43 -0800 Subject: [PATCH 6/6] simplify aiohttp test fixture --- tests/integrations/aiohttp/test_aiohttp.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index 1a2b39c978..b689e3af17 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -474,22 +474,17 @@ async def hello(request): assert error_event["contexts"]["trace"]["trace_id"] == trace_id -if sys.version_info >= (3, 12): - - @pytest.fixture - def asyncio_loop(event_loop): - yield event_loop - -else: - +if sys.version_info < (3, 12): + # `loop` was deprecated in `pytest-aiohttp` + # in favor of `event_loop` from `pytest-asyncio` @pytest.fixture - def asyncio_loop(loop): + def event_loop(loop): yield loop @pytest.mark.asyncio async def test_crumb_capture( - sentry_init, aiohttp_raw_server, aiohttp_client, asyncio_loop, capture_events + sentry_init, aiohttp_raw_server, aiohttp_client, event_loop, capture_events ): def before_breadcrumb(crumb, hint): crumb["data"]["extra"] = "foo"