Skip to content

Commit 1cef931

Browse files
Merge remote-tracking branch 'origin/master' into ci/ruff-unused-noqa
# Conflicts: # pyproject.toml # tests/integrations/celery/test_celery.py # tests/integrations/stdlib/test_httplib.py
2 parents 8f24d98 + ddd4948 commit 1cef931

13 files changed

Lines changed: 42 additions & 41 deletions

File tree

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ select = [
300300
"F", # Pyflakes (same as flake8 default)
301301
"I",
302302
"T20", # print() and pprint() calls
303+
"PT011", # pytest.raises() too broad
303304
"RUF100", # Unused noqa directive
304305
]
305306

‎tests/integrations/asgi/test_asgi.py‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,12 @@ async def app(scope, receive, send):
184184

185185

186186
def test_invalid_transaction_style(asgi3_app):
187-
with pytest.raises(ValueError) as exp:
187+
with pytest.raises(
188+
ValueError,
189+
match=r"Invalid value for transaction_style: URL \(must be in \('endpoint', 'url'\)\)",
190+
):
188191
SentryAsgiMiddleware(asgi3_app, transaction_style="URL")
189192

190-
assert (
191-
str(exp.value)
192-
== "Invalid value for transaction_style: URL (must be in ('endpoint', 'url'))"
193-
)
194-
195193

196194
@pytest.mark.asyncio
197195
@pytest.mark.parametrize(
@@ -552,7 +550,7 @@ async def test_websocket(
552550

553551
request_url = "/ws"
554552

555-
with pytest.raises(ValueError):
553+
with pytest.raises(ValueError, match="Oh no"):
556554
client = TestClient(asgi3_ws_app)
557555
if span_streaming:
558556
items = capture_items("event", "span")

‎tests/integrations/boto3/test_client.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ def fail_attribute_extraction(exception):
662662
)
663663

664664
def invoke_failing_client_method():
665-
with pytest.raises(ValueError) as exc_info:
665+
with pytest.raises(ValueError, match="parameter processing failed") as exc_info:
666666
client.head_object(Bucket="bucket", Key="foo")
667667
assert exc_info.value is original_exception
668668

@@ -750,7 +750,7 @@ def respond(request, **kwargs):
750750

751751
def invoke_client_method_and_read_body():
752752
body = client.get_object(Bucket="bucket", Key="foo")["Body"]
753-
with pytest.raises(OSError) as exc_info:
753+
with pytest.raises(OSError, match="stream read failed") as exc_info:
754754
body.read()
755755
assert exc_info.value is original_exception
756756

‎tests/integrations/celery/test_celery.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,7 @@ def dummy_task(self):
573573
# Curious: Cannot use delay() here or py2.7-celery-4.2 crashes
574574
res = dummy_task.apply_async()
575575

576-
with pytest.raises(Exception):
577-
# Celery 4.1 raises a gibberish exception
576+
with pytest.raises(ZeroDivisionError):
578577
res.wait()
579578

580579
# if this is nonempty, the worker never really forked

‎tests/integrations/chalice/test_chalice.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,8 @@ def every_hour(event):
117117
"id": "event-id",
118118
"resources": ["arn:aws:events:us-west-1:120987654312:rule/my-schedule"],
119119
}
120-
with pytest.raises(Exception) as exc_info:
120+
with pytest.raises(Exception, match="schedule event!"):
121121
every_hour(lambda_event, context=context)
122-
assert str(exc_info.value) == "schedule event!"
123122

124123

125124
@pytest.mark.skipif(

‎tests/integrations/langchain/test_langchain.py‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,14 +3623,18 @@ def _llm_type(self) -> str:
36233623
if span_streaming or stream_gen_ai_spans:
36243624
items = capture_items("event")
36253625

3626-
with start_transaction(), pytest.raises(ValueError):
3626+
with start_transaction(), pytest.raises(
3627+
ValueError, match="API rate limit error"
3628+
):
36273629
list(agent_executor.stream({"input": "How many letters in the word eudca"}))
36283630

36293631
(error,) = (item.payload for item in items)
36303632
else:
36313633
events = capture_events()
36323634

3633-
with start_transaction(), pytest.raises(ValueError):
3635+
with start_transaction(), pytest.raises(
3636+
ValueError, match="API rate limit error"
3637+
):
36343638
list(agent_executor.stream({"input": "How many letters in the word eudca"}))
36353639

36363640
error = events[0]
@@ -3698,7 +3702,7 @@ def _llm_type(self) -> str:
36983702
agent=agent, tools=[get_word_length], verbose=True
36993703
)
37003704

3701-
with pytest.raises(ValueError):
3705+
with pytest.raises(ValueError, match="API rate limit error"):
37023706
list(
37033707
agent_executor.stream(
37043708
{"input": "How many letters in the word eudca"}
@@ -3737,7 +3741,7 @@ def _llm_type(self) -> str:
37373741
agent=agent, tools=[get_word_length], verbose=True
37383742
)
37393743

3740-
with pytest.raises(ValueError):
3744+
with pytest.raises(ValueError, match="API rate limit error"):
37413745
list(
37423746
agent_executor.stream(
37433747
{"input": "How many letters in the word eudca"}
@@ -3777,7 +3781,7 @@ def _llm_type(self) -> str:
37773781
agent=agent, tools=[get_word_length], verbose=True
37783782
)
37793783

3780-
with pytest.raises(ValueError):
3784+
with pytest.raises(ValueError, match="API rate limit error"):
37813785
list(
37823786
agent_executor.stream(
37833787
{"input": "How many letters in the word eudca"}
@@ -3857,7 +3861,9 @@ def test_langchain_tool_error(
38573861

38583862
with patch.object(
38593863
llm.client._client._client, "send", side_effect=[tool_response]
3860-
), start_transaction(name="tx"), pytest.raises(ValueError):
3864+
), start_transaction(name="tx"), pytest.raises(
3865+
ValueError, match="Tool execution failed"
3866+
):
38613867
agent.invoke({"messages": [HumanMessage(content="hi")]})
38623868

38633869
error_events = [event for event in events if event.get("level") == "error"]

‎tests/integrations/stdlib/test_httplib.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import socket
44
import time
5-
from http.client import HTTPConnection, HTTPSConnection
5+
from http.client import CannotSendRequest, HTTPConnection, HTTPSConnection
66
from http.server import BaseHTTPRequestHandler, HTTPServer
77
from socket import SocketIO
88
from threading import Thread
@@ -356,7 +356,7 @@ def test_httplib_misuse(sentry_init, capture_events, request):
356356

357357
conn.request("GET", "/200")
358358

359-
with pytest.raises(Exception):
359+
with pytest.raises(CannotSendRequest):
360360
# This raises an exception, because we didn't call `getresponse` for
361361
# the previous request yet.
362362
#

‎tests/integrations/wsgi/test_wsgi.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def dogpark(environ, start_response):
165165
else:
166166
events = capture_events()
167167

168-
with pytest.raises(ValueError):
168+
with pytest.raises(ValueError, match="Fetch aborted"):
169169
client.get("http://dogs.are.great/sit/stay/rollover/")
170170

171171
sentry_sdk.flush()
@@ -300,7 +300,7 @@ def dogpark(environ, start_response):
300300
else:
301301
events = capture_events()
302302

303-
with pytest.raises(ValueError):
303+
with pytest.raises(ValueError, match="Fetch aborted"):
304304
client.get("http://dogs.are.great/sit/stay/rollover/")
305305

306306
sentry_sdk.flush()
@@ -359,7 +359,7 @@ def dogpark(environ, start_response):
359359
client = Client(app)
360360
events = capture_events()
361361

362-
with pytest.raises(ValueError):
362+
with pytest.raises(ValueError, match="Fetch aborted"):
363363
client.get("http://dogs.are.great/sit/stay/rollover/")
364364

365365
msg_event, error_event = events
@@ -397,7 +397,7 @@ def dogpark(environ, start_response):
397397
trace_id = "582b43a4192642f0b136d5159a501701"
398398
sentry_trace_header = "{}-{}-{}".format(trace_id, "6e8f22c393e68f19", 1)
399399

400-
with pytest.raises(ValueError):
400+
with pytest.raises(ValueError, match="Fetch aborted"):
401401
client.get(
402402
"http://dogs.are.great/sit/stay/rollover/",
403403
headers={"sentry-trace": sentry_trace_header},
@@ -444,7 +444,7 @@ def dogpark(environ, start_response):
444444
trace_id = "582b43a4192642f0b136d5159a501701"
445445
sentry_trace_header = "{}-{}-{}".format(trace_id, "6e8f22c393e68f19", 1)
446446

447-
with pytest.raises(ValueError):
447+
with pytest.raises(ValueError, match="Fetch aborted"):
448448
client.get(
449449
"http://dogs.are.great/sit/stay/rollover/",
450450
headers={"sentry-trace": sentry_trace_header},

‎tests/profiler/test_continuous_profiler.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def client_options(
8989
],
9090
)
9191
def test_continuous_profiler_invalid_mode(mode, make_options, teardown_profiling):
92-
with pytest.raises(ValueError):
92+
with pytest.raises(ValueError, match="Unknown continuous profiler mode: foo"):
9393
setup_continuous_profiler(
9494
make_options(mode=mode),
9595
mock_sdk_info,

‎tests/profiler/test_transaction_profiler.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def experimental_options(mode=None, sample_rate=None):
6262
],
6363
)
6464
def test_profiler_invalid_mode(mode, make_options, teardown_profiling):
65-
with pytest.raises(ValueError):
65+
with pytest.raises(ValueError, match="Unknown profiler mode: foo"):
6666
setup_profiler(make_options(mode))
6767

6868

0 commit comments

Comments
 (0)