From 1c36bb2c8b748f60e973d191016f8610f8270915 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 09:54:34 +0000 Subject: [PATCH 1/2] ci(ruff): Enable PT011 for overly broad pytest.raises() Existing cases get a noqa comment, so only new tests are checked. Co-Authored-By: Ivana Kellyer <131587164+sentrivana@users.noreply.github.com> --- pyproject.toml | 1 + tests/integrations/asgi/test_asgi.py | 4 ++-- tests/integrations/boto3/test_client.py | 4 ++-- tests/integrations/celery/test_celery.py | 2 +- tests/integrations/chalice/test_chalice.py | 2 +- tests/integrations/langchain/test_langchain.py | 12 ++++++------ tests/integrations/stdlib/test_httplib.py | 2 +- tests/integrations/wsgi/test_wsgi.py | 10 +++++----- tests/profiler/test_continuous_profiler.py | 2 +- tests/profiler/test_transaction_profiler.py | 2 +- tests/test_data_collection.py | 6 +++--- tests/test_utils.py | 6 +++--- tests/tracing/test_span_streaming.py | 2 +- 13 files changed, 28 insertions(+), 27 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index cfac620006..cb16429874 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -301,6 +301,7 @@ select = [ "I", # Note: B and N rules are NOT enabled by default in flake8 # They were only active through the plugins, which may not have been fully enabled + "PT011", # pytest.raises() too broad ] # Use ONLY the same ignores as the original flake8 config + compatibility for this codebase diff --git a/tests/integrations/asgi/test_asgi.py b/tests/integrations/asgi/test_asgi.py index cae3a24cb4..d06f09b8ac 100644 --- a/tests/integrations/asgi/test_asgi.py +++ b/tests/integrations/asgi/test_asgi.py @@ -184,7 +184,7 @@ async def app(scope, receive, send): def test_invalid_transaction_style(asgi3_app): - with pytest.raises(ValueError) as exp: + with pytest.raises(ValueError) as exp: # noqa: PT011 SentryAsgiMiddleware(asgi3_app, transaction_style="URL") assert ( @@ -552,7 +552,7 @@ async def test_websocket( request_url = "/ws" - with pytest.raises(ValueError): + with pytest.raises(ValueError): # noqa: PT011 client = TestClient(asgi3_ws_app) if span_streaming: items = capture_items("event", "span") diff --git a/tests/integrations/boto3/test_client.py b/tests/integrations/boto3/test_client.py index 0b864ac1e0..69fc62e958 100644 --- a/tests/integrations/boto3/test_client.py +++ b/tests/integrations/boto3/test_client.py @@ -662,7 +662,7 @@ def fail_attribute_extraction(exception): ) def invoke_failing_client_method(): - with pytest.raises(ValueError) as exc_info: + with pytest.raises(ValueError) as exc_info: # noqa: PT011 client.head_object(Bucket="bucket", Key="foo") assert exc_info.value is original_exception @@ -750,7 +750,7 @@ def respond(request, **kwargs): def invoke_client_method_and_read_body(): body = client.get_object(Bucket="bucket", Key="foo")["Body"] - with pytest.raises(OSError) as exc_info: + with pytest.raises(OSError) as exc_info: # noqa: PT011 body.read() assert exc_info.value is original_exception diff --git a/tests/integrations/celery/test_celery.py b/tests/integrations/celery/test_celery.py index 56c7e9b781..43b914343c 100644 --- a/tests/integrations/celery/test_celery.py +++ b/tests/integrations/celery/test_celery.py @@ -573,7 +573,7 @@ def dummy_task(self): # Curious: Cannot use delay() here or py2.7-celery-4.2 crashes res = dummy_task.apply_async() - with pytest.raises(Exception): # noqa: B017 + with pytest.raises(Exception): # noqa: B017, PT011 # Celery 4.1 raises a gibberish exception res.wait() diff --git a/tests/integrations/chalice/test_chalice.py b/tests/integrations/chalice/test_chalice.py index 69f023efd4..6deb002a26 100644 --- a/tests/integrations/chalice/test_chalice.py +++ b/tests/integrations/chalice/test_chalice.py @@ -117,7 +117,7 @@ def every_hour(event): "id": "event-id", "resources": ["arn:aws:events:us-west-1:120987654312:rule/my-schedule"], } - with pytest.raises(Exception) as exc_info: + with pytest.raises(Exception) as exc_info: # noqa: PT011 every_hour(lambda_event, context=context) assert str(exc_info.value) == "schedule event!" diff --git a/tests/integrations/langchain/test_langchain.py b/tests/integrations/langchain/test_langchain.py index fe3886ce02..75d51a4be7 100644 --- a/tests/integrations/langchain/test_langchain.py +++ b/tests/integrations/langchain/test_langchain.py @@ -3623,14 +3623,14 @@ def _llm_type(self) -> str: if span_streaming or stream_gen_ai_spans: items = capture_items("event") - with start_transaction(), pytest.raises(ValueError): + with start_transaction(), pytest.raises(ValueError): # noqa: PT011 list(agent_executor.stream({"input": "How many letters in the word eudca"})) (error,) = (item.payload for item in items) else: events = capture_events() - with start_transaction(), pytest.raises(ValueError): + with start_transaction(), pytest.raises(ValueError): # noqa: PT011 list(agent_executor.stream({"input": "How many letters in the word eudca"})) error = events[0] @@ -3698,7 +3698,7 @@ def _llm_type(self) -> str: agent=agent, tools=[get_word_length], verbose=True ) - with pytest.raises(ValueError): + with pytest.raises(ValueError): # noqa: PT011 list( agent_executor.stream( {"input": "How many letters in the word eudca"} @@ -3737,7 +3737,7 @@ def _llm_type(self) -> str: agent=agent, tools=[get_word_length], verbose=True ) - with pytest.raises(ValueError): + with pytest.raises(ValueError): # noqa: PT011 list( agent_executor.stream( {"input": "How many letters in the word eudca"} @@ -3777,7 +3777,7 @@ def _llm_type(self) -> str: agent=agent, tools=[get_word_length], verbose=True ) - with pytest.raises(ValueError): + with pytest.raises(ValueError): # noqa: PT011 list( agent_executor.stream( {"input": "How many letters in the word eudca"} @@ -3857,7 +3857,7 @@ def test_langchain_tool_error( with patch.object( llm.client._client._client, "send", side_effect=[tool_response] - ), start_transaction(name="tx"), pytest.raises(ValueError): + ), start_transaction(name="tx"), pytest.raises(ValueError): # noqa: PT011 agent.invoke({"messages": [HumanMessage(content="hi")]}) error_events = [event for event in events if event.get("level") == "error"] diff --git a/tests/integrations/stdlib/test_httplib.py b/tests/integrations/stdlib/test_httplib.py index 068714d4dc..98ea430b96 100644 --- a/tests/integrations/stdlib/test_httplib.py +++ b/tests/integrations/stdlib/test_httplib.py @@ -356,7 +356,7 @@ def test_httplib_misuse(sentry_init, capture_events, request): conn.request("GET", "/200") - with pytest.raises(Exception): # noqa: B017 + with pytest.raises(Exception): # noqa: B017, PT011 # This raises an exception, because we didn't call `getresponse` for # the previous request yet. # diff --git a/tests/integrations/wsgi/test_wsgi.py b/tests/integrations/wsgi/test_wsgi.py index 2cda3a1b98..b45661f33d 100644 --- a/tests/integrations/wsgi/test_wsgi.py +++ b/tests/integrations/wsgi/test_wsgi.py @@ -165,7 +165,7 @@ def dogpark(environ, start_response): else: events = capture_events() - with pytest.raises(ValueError): + with pytest.raises(ValueError): # noqa: PT011 client.get("http://dogs.are.great/sit/stay/rollover/") sentry_sdk.flush() @@ -300,7 +300,7 @@ def dogpark(environ, start_response): else: events = capture_events() - with pytest.raises(ValueError): + with pytest.raises(ValueError): # noqa: PT011 client.get("http://dogs.are.great/sit/stay/rollover/") sentry_sdk.flush() @@ -359,7 +359,7 @@ def dogpark(environ, start_response): client = Client(app) events = capture_events() - with pytest.raises(ValueError): + with pytest.raises(ValueError): # noqa: PT011 client.get("http://dogs.are.great/sit/stay/rollover/") msg_event, error_event = events @@ -397,7 +397,7 @@ def dogpark(environ, start_response): trace_id = "582b43a4192642f0b136d5159a501701" sentry_trace_header = "{}-{}-{}".format(trace_id, "6e8f22c393e68f19", 1) - with pytest.raises(ValueError): + with pytest.raises(ValueError): # noqa: PT011 client.get( "http://dogs.are.great/sit/stay/rollover/", headers={"sentry-trace": sentry_trace_header}, @@ -444,7 +444,7 @@ def dogpark(environ, start_response): trace_id = "582b43a4192642f0b136d5159a501701" sentry_trace_header = "{}-{}-{}".format(trace_id, "6e8f22c393e68f19", 1) - with pytest.raises(ValueError): + with pytest.raises(ValueError): # noqa: PT011 client.get( "http://dogs.are.great/sit/stay/rollover/", headers={"sentry-trace": sentry_trace_header}, diff --git a/tests/profiler/test_continuous_profiler.py b/tests/profiler/test_continuous_profiler.py index 782d6fb846..a1ea0dc7d7 100644 --- a/tests/profiler/test_continuous_profiler.py +++ b/tests/profiler/test_continuous_profiler.py @@ -89,7 +89,7 @@ def client_options( ], ) def test_continuous_profiler_invalid_mode(mode, make_options, teardown_profiling): - with pytest.raises(ValueError): + with pytest.raises(ValueError): # noqa: PT011 setup_continuous_profiler( make_options(mode=mode), mock_sdk_info, diff --git a/tests/profiler/test_transaction_profiler.py b/tests/profiler/test_transaction_profiler.py index 742555f003..0f990e514a 100644 --- a/tests/profiler/test_transaction_profiler.py +++ b/tests/profiler/test_transaction_profiler.py @@ -62,7 +62,7 @@ def experimental_options(mode=None, sample_rate=None): ], ) def test_profiler_invalid_mode(mode, make_options, teardown_profiling): - with pytest.raises(ValueError): + with pytest.raises(ValueError): # noqa: PT011 setup_profiler(make_options(mode)) diff --git a/tests/test_data_collection.py b/tests/test_data_collection.py index ff1eed11e0..34b433a56b 100644 --- a/tests/test_data_collection.py +++ b/tests/test_data_collection.py @@ -8,12 +8,12 @@ def test_kvcb_invalid_mode(sentry_init): - with pytest.raises(ValueError): + with pytest.raises(ValueError): # noqa: PT011 sentry_init(data_collection={"cookies": {"mode": "nope"}}) # type: ignore Purposely ignoring to test invalid option def test_stack_frame_variables_invalid_mode(sentry_init): - with pytest.raises(ValueError): + with pytest.raises(ValueError): # noqa: PT011 sentry_init(data_collection={"stack_frame_variables": {"mode": "nope"}}) @@ -28,7 +28,7 @@ def test_stack_frame_variables_invalid_mode(sentry_init): ], ) def test_frame_context_lines_invalid_value(sentry_init, value): - with pytest.raises(ValueError): + with pytest.raises(ValueError): # noqa: PT011 sentry_init(data_collection={"frame_context_lines": value}) diff --git a/tests/test_utils.py b/tests/test_utils.py index 0bea9a6705..2201a6a8cc 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -913,12 +913,12 @@ def test_is_sentry_url_no_client(): ], ) def test_get_error_message(error, expected_result): - with pytest.raises(BaseException) as exc_value: + with pytest.raises(BaseException) as exc_value: # noqa: PT011 exc_value.message = error raise Exception assert get_error_message(exc_value) == expected_result(exc_value) - with pytest.raises(BaseException) as exc_value: + with pytest.raises(BaseException) as exc_value: # noqa: PT011 exc_value.detail = error raise Exception assert get_error_message(exc_value) == expected_result(exc_value) @@ -1296,7 +1296,7 @@ def test_exc_info_from_error_dont_get_an_exc(): class NotAnException: pass - with pytest.raises(ValueError) as exc: + with pytest.raises(ValueError) as exc: # noqa: PT011 exc_info_from_error(NotAnException()) assert "Expected Exception object to report, got Date: Mon, 16 Nov 2026 10:15:28 +0000 Subject: [PATCH 2/2] test: Narrow broad pytest.raises() instead of ignoring PT011 Add match= with the expected message to every pytest.raises() that PT011 flagged, and drop the noqa comments. Where a test already asserted on the message afterwards, the assertion moves into match=. - test_get_error_message used pytest.raises() only as an attribute holder, so it now builds a plain Exception instead. - The httplib test expects http.client.CannotSendRequest. - The skipped celery redis-backend test expects the task's ZeroDivisionError; the Celery 4.1 workaround predates the minimum supported Celery version (4.4.7). Co-Authored-By: Ivana Kellyer --- tests/integrations/asgi/test_asgi.py | 12 +++++------- tests/integrations/boto3/test_client.py | 4 ++-- tests/integrations/celery/test_celery.py | 3 +-- tests/integrations/chalice/test_chalice.py | 3 +-- tests/integrations/langchain/test_langchain.py | 18 ++++++++++++------ tests/integrations/stdlib/test_httplib.py | 4 ++-- tests/integrations/wsgi/test_wsgi.py | 10 +++++----- tests/profiler/test_continuous_profiler.py | 2 +- tests/profiler/test_transaction_profiler.py | 2 +- tests/test_data_collection.py | 6 +++--- tests/test_utils.py | 16 +++++++--------- tests/tracing/test_span_streaming.py | 2 +- 12 files changed, 41 insertions(+), 41 deletions(-) diff --git a/tests/integrations/asgi/test_asgi.py b/tests/integrations/asgi/test_asgi.py index d06f09b8ac..97222edebc 100644 --- a/tests/integrations/asgi/test_asgi.py +++ b/tests/integrations/asgi/test_asgi.py @@ -184,14 +184,12 @@ async def app(scope, receive, send): def test_invalid_transaction_style(asgi3_app): - with pytest.raises(ValueError) as exp: # noqa: PT011 + with pytest.raises( + ValueError, + match=r"Invalid value for transaction_style: URL \(must be in \('endpoint', 'url'\)\)", + ): SentryAsgiMiddleware(asgi3_app, transaction_style="URL") - assert ( - str(exp.value) - == "Invalid value for transaction_style: URL (must be in ('endpoint', 'url'))" - ) - @pytest.mark.asyncio @pytest.mark.parametrize( @@ -552,7 +550,7 @@ async def test_websocket( request_url = "/ws" - with pytest.raises(ValueError): # noqa: PT011 + with pytest.raises(ValueError, match="Oh no"): client = TestClient(asgi3_ws_app) if span_streaming: items = capture_items("event", "span") diff --git a/tests/integrations/boto3/test_client.py b/tests/integrations/boto3/test_client.py index 69fc62e958..25ec8751f7 100644 --- a/tests/integrations/boto3/test_client.py +++ b/tests/integrations/boto3/test_client.py @@ -662,7 +662,7 @@ def fail_attribute_extraction(exception): ) def invoke_failing_client_method(): - with pytest.raises(ValueError) as exc_info: # noqa: PT011 + with pytest.raises(ValueError, match="parameter processing failed") as exc_info: client.head_object(Bucket="bucket", Key="foo") assert exc_info.value is original_exception @@ -750,7 +750,7 @@ def respond(request, **kwargs): def invoke_client_method_and_read_body(): body = client.get_object(Bucket="bucket", Key="foo")["Body"] - with pytest.raises(OSError) as exc_info: # noqa: PT011 + with pytest.raises(OSError, match="stream read failed") as exc_info: body.read() assert exc_info.value is original_exception diff --git a/tests/integrations/celery/test_celery.py b/tests/integrations/celery/test_celery.py index 43b914343c..cd9d716cd2 100644 --- a/tests/integrations/celery/test_celery.py +++ b/tests/integrations/celery/test_celery.py @@ -573,8 +573,7 @@ def dummy_task(self): # Curious: Cannot use delay() here or py2.7-celery-4.2 crashes res = dummy_task.apply_async() - with pytest.raises(Exception): # noqa: B017, PT011 - # Celery 4.1 raises a gibberish exception + with pytest.raises(ZeroDivisionError): res.wait() # if this is nonempty, the worker never really forked diff --git a/tests/integrations/chalice/test_chalice.py b/tests/integrations/chalice/test_chalice.py index 6deb002a26..5f6099b6fd 100644 --- a/tests/integrations/chalice/test_chalice.py +++ b/tests/integrations/chalice/test_chalice.py @@ -117,9 +117,8 @@ def every_hour(event): "id": "event-id", "resources": ["arn:aws:events:us-west-1:120987654312:rule/my-schedule"], } - with pytest.raises(Exception) as exc_info: # noqa: PT011 + with pytest.raises(Exception, match="schedule event!"): every_hour(lambda_event, context=context) - assert str(exc_info.value) == "schedule event!" @pytest.mark.skipif( diff --git a/tests/integrations/langchain/test_langchain.py b/tests/integrations/langchain/test_langchain.py index 75d51a4be7..0863aa5e8e 100644 --- a/tests/integrations/langchain/test_langchain.py +++ b/tests/integrations/langchain/test_langchain.py @@ -3623,14 +3623,18 @@ def _llm_type(self) -> str: if span_streaming or stream_gen_ai_spans: items = capture_items("event") - with start_transaction(), pytest.raises(ValueError): # noqa: PT011 + with start_transaction(), pytest.raises( + ValueError, match="API rate limit error" + ): list(agent_executor.stream({"input": "How many letters in the word eudca"})) (error,) = (item.payload for item in items) else: events = capture_events() - with start_transaction(), pytest.raises(ValueError): # noqa: PT011 + with start_transaction(), pytest.raises( + ValueError, match="API rate limit error" + ): list(agent_executor.stream({"input": "How many letters in the word eudca"})) error = events[0] @@ -3698,7 +3702,7 @@ def _llm_type(self) -> str: agent=agent, tools=[get_word_length], verbose=True ) - with pytest.raises(ValueError): # noqa: PT011 + with pytest.raises(ValueError, match="API rate limit error"): list( agent_executor.stream( {"input": "How many letters in the word eudca"} @@ -3737,7 +3741,7 @@ def _llm_type(self) -> str: agent=agent, tools=[get_word_length], verbose=True ) - with pytest.raises(ValueError): # noqa: PT011 + with pytest.raises(ValueError, match="API rate limit error"): list( agent_executor.stream( {"input": "How many letters in the word eudca"} @@ -3777,7 +3781,7 @@ def _llm_type(self) -> str: agent=agent, tools=[get_word_length], verbose=True ) - with pytest.raises(ValueError): # noqa: PT011 + with pytest.raises(ValueError, match="API rate limit error"): list( agent_executor.stream( {"input": "How many letters in the word eudca"} @@ -3857,7 +3861,9 @@ def test_langchain_tool_error( with patch.object( llm.client._client._client, "send", side_effect=[tool_response] - ), start_transaction(name="tx"), pytest.raises(ValueError): # noqa: PT011 + ), start_transaction(name="tx"), pytest.raises( + ValueError, match="Tool execution failed" + ): agent.invoke({"messages": [HumanMessage(content="hi")]}) error_events = [event for event in events if event.get("level") == "error"] diff --git a/tests/integrations/stdlib/test_httplib.py b/tests/integrations/stdlib/test_httplib.py index 98ea430b96..dc9bd2add7 100644 --- a/tests/integrations/stdlib/test_httplib.py +++ b/tests/integrations/stdlib/test_httplib.py @@ -2,7 +2,7 @@ import os import socket import time -from http.client import HTTPConnection, HTTPSConnection +from http.client import CannotSendRequest, HTTPConnection, HTTPSConnection from http.server import BaseHTTPRequestHandler, HTTPServer from socket import SocketIO from threading import Thread @@ -356,7 +356,7 @@ def test_httplib_misuse(sentry_init, capture_events, request): conn.request("GET", "/200") - with pytest.raises(Exception): # noqa: B017, PT011 + with pytest.raises(CannotSendRequest): # This raises an exception, because we didn't call `getresponse` for # the previous request yet. # diff --git a/tests/integrations/wsgi/test_wsgi.py b/tests/integrations/wsgi/test_wsgi.py index b45661f33d..4eee854ae8 100644 --- a/tests/integrations/wsgi/test_wsgi.py +++ b/tests/integrations/wsgi/test_wsgi.py @@ -165,7 +165,7 @@ def dogpark(environ, start_response): else: events = capture_events() - with pytest.raises(ValueError): # noqa: PT011 + with pytest.raises(ValueError, match="Fetch aborted"): client.get("http://dogs.are.great/sit/stay/rollover/") sentry_sdk.flush() @@ -300,7 +300,7 @@ def dogpark(environ, start_response): else: events = capture_events() - with pytest.raises(ValueError): # noqa: PT011 + with pytest.raises(ValueError, match="Fetch aborted"): client.get("http://dogs.are.great/sit/stay/rollover/") sentry_sdk.flush() @@ -359,7 +359,7 @@ def dogpark(environ, start_response): client = Client(app) events = capture_events() - with pytest.raises(ValueError): # noqa: PT011 + with pytest.raises(ValueError, match="Fetch aborted"): client.get("http://dogs.are.great/sit/stay/rollover/") msg_event, error_event = events @@ -397,7 +397,7 @@ def dogpark(environ, start_response): trace_id = "582b43a4192642f0b136d5159a501701" sentry_trace_header = "{}-{}-{}".format(trace_id, "6e8f22c393e68f19", 1) - with pytest.raises(ValueError): # noqa: PT011 + with pytest.raises(ValueError, match="Fetch aborted"): client.get( "http://dogs.are.great/sit/stay/rollover/", headers={"sentry-trace": sentry_trace_header}, @@ -444,7 +444,7 @@ def dogpark(environ, start_response): trace_id = "582b43a4192642f0b136d5159a501701" sentry_trace_header = "{}-{}-{}".format(trace_id, "6e8f22c393e68f19", 1) - with pytest.raises(ValueError): # noqa: PT011 + with pytest.raises(ValueError, match="Fetch aborted"): client.get( "http://dogs.are.great/sit/stay/rollover/", headers={"sentry-trace": sentry_trace_header}, diff --git a/tests/profiler/test_continuous_profiler.py b/tests/profiler/test_continuous_profiler.py index a1ea0dc7d7..550465dfff 100644 --- a/tests/profiler/test_continuous_profiler.py +++ b/tests/profiler/test_continuous_profiler.py @@ -89,7 +89,7 @@ def client_options( ], ) def test_continuous_profiler_invalid_mode(mode, make_options, teardown_profiling): - with pytest.raises(ValueError): # noqa: PT011 + with pytest.raises(ValueError, match="Unknown continuous profiler mode: foo"): setup_continuous_profiler( make_options(mode=mode), mock_sdk_info, diff --git a/tests/profiler/test_transaction_profiler.py b/tests/profiler/test_transaction_profiler.py index 0f990e514a..6929dc86fb 100644 --- a/tests/profiler/test_transaction_profiler.py +++ b/tests/profiler/test_transaction_profiler.py @@ -62,7 +62,7 @@ def experimental_options(mode=None, sample_rate=None): ], ) def test_profiler_invalid_mode(mode, make_options, teardown_profiling): - with pytest.raises(ValueError): # noqa: PT011 + with pytest.raises(ValueError, match="Unknown profiler mode: foo"): setup_profiler(make_options(mode)) diff --git a/tests/test_data_collection.py b/tests/test_data_collection.py index 34b433a56b..238a81caa6 100644 --- a/tests/test_data_collection.py +++ b/tests/test_data_collection.py @@ -8,12 +8,12 @@ def test_kvcb_invalid_mode(sentry_init): - with pytest.raises(ValueError): # noqa: PT011 + with pytest.raises(ValueError, match="Invalid collection mode 'nope'"): sentry_init(data_collection={"cookies": {"mode": "nope"}}) # type: ignore Purposely ignoring to test invalid option def test_stack_frame_variables_invalid_mode(sentry_init): - with pytest.raises(ValueError): # noqa: PT011 + with pytest.raises(ValueError, match="Invalid collection mode 'nope'"): sentry_init(data_collection={"stack_frame_variables": {"mode": "nope"}}) @@ -28,7 +28,7 @@ def test_stack_frame_variables_invalid_mode(sentry_init): ], ) def test_frame_context_lines_invalid_value(sentry_init, value): - with pytest.raises(ValueError): # noqa: PT011 + with pytest.raises(ValueError, match="Invalid `frame_context_lines` value"): sentry_init(data_collection={"frame_context_lines": value}) diff --git a/tests/test_utils.py b/tests/test_utils.py index 2201a6a8cc..d5b9713cce 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -913,14 +913,12 @@ def test_is_sentry_url_no_client(): ], ) def test_get_error_message(error, expected_result): - with pytest.raises(BaseException) as exc_value: # noqa: PT011 - exc_value.message = error - raise Exception + exc_value = Exception() + exc_value.message = error assert get_error_message(exc_value) == expected_result(exc_value) - with pytest.raises(BaseException) as exc_value: # noqa: PT011 - exc_value.detail = error - raise Exception + exc_value = Exception() + exc_value.detail = error assert get_error_message(exc_value) == expected_result(exc_value) @@ -1296,11 +1294,11 @@ def test_exc_info_from_error_dont_get_an_exc(): class NotAnException: pass - with pytest.raises(ValueError) as exc: # noqa: PT011 + with pytest.raises( + ValueError, match="Expected Exception object to report, got