Skip to content

Commit f798939

Browse files
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>
1 parent 38a3fa3 commit f798939

13 files changed

Lines changed: 28 additions & 27 deletions

File tree

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ select = [
304304
"RUF100", # Unused noqa directive
305305
"T20", # print() and pprint() calls
306306
"PLC0415", # Import not at the top level of the file
307+
"PT011", # pytest.raises() too broad
307308
]
308309

309310
# Use ONLY the same ignores as the original flake8 config + compatibility for this codebase

‎tests/integrations/asgi/test_asgi.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ 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(ValueError) as exp: # noqa: PT011
188188
SentryAsgiMiddleware(asgi3_app, transaction_style="URL")
189189

190190
assert (
@@ -552,7 +552,7 @@ async def test_websocket(
552552

553553
request_url = "/ws"
554554

555-
with pytest.raises(ValueError):
555+
with pytest.raises(ValueError): # noqa: PT011
556556
client = TestClient(asgi3_ws_app)
557557
if span_streaming:
558558
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) as exc_info: # noqa: PT011
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) as exc_info: # noqa: PT011
754754
body.read()
755755
assert exc_info.value is original_exception
756756

‎tests/integrations/celery/test_celery.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +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):
576+
with pytest.raises(Exception): # noqa: PT011
577577
# Celery 4.1 raises a gibberish exception
578578
res.wait()
579579

‎tests/integrations/chalice/test_chalice.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ 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) as exc_info: # noqa: PT011
121121
every_hour(lambda_event, context=context)
122122
assert str(exc_info.value) == "schedule event!"
123123

‎tests/integrations/langchain/test_langchain.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,14 +3623,14 @@ 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(ValueError): # noqa: PT011
36273627
list(agent_executor.stream({"input": "How many letters in the word eudca"}))
36283628

36293629
(error,) = (item.payload for item in items)
36303630
else:
36313631
events = capture_events()
36323632

3633-
with start_transaction(), pytest.raises(ValueError):
3633+
with start_transaction(), pytest.raises(ValueError): # noqa: PT011
36343634
list(agent_executor.stream({"input": "How many letters in the word eudca"}))
36353635

36363636
error = events[0]
@@ -3698,7 +3698,7 @@ def _llm_type(self) -> str:
36983698
agent=agent, tools=[get_word_length], verbose=True
36993699
)
37003700

3701-
with pytest.raises(ValueError):
3701+
with pytest.raises(ValueError): # noqa: PT011
37023702
list(
37033703
agent_executor.stream(
37043704
{"input": "How many letters in the word eudca"}
@@ -3737,7 +3737,7 @@ def _llm_type(self) -> str:
37373737
agent=agent, tools=[get_word_length], verbose=True
37383738
)
37393739

3740-
with pytest.raises(ValueError):
3740+
with pytest.raises(ValueError): # noqa: PT011
37413741
list(
37423742
agent_executor.stream(
37433743
{"input": "How many letters in the word eudca"}
@@ -3777,7 +3777,7 @@ def _llm_type(self) -> str:
37773777
agent=agent, tools=[get_word_length], verbose=True
37783778
)
37793779

3780-
with pytest.raises(ValueError):
3780+
with pytest.raises(ValueError): # noqa: PT011
37813781
list(
37823782
agent_executor.stream(
37833783
{"input": "How many letters in the word eudca"}
@@ -3857,7 +3857,7 @@ def test_langchain_tool_error(
38573857

38583858
with patch.object(
38593859
llm.client._client._client, "send", side_effect=[tool_response]
3860-
), start_transaction(name="tx"), pytest.raises(ValueError):
3860+
), start_transaction(name="tx"), pytest.raises(ValueError): # noqa: PT011
38613861
agent.invoke({"messages": [HumanMessage(content="hi")]})
38623862

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

‎tests/integrations/stdlib/test_httplib.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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(Exception): # noqa: PT011
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): # noqa: PT011
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): # noqa: PT011
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): # noqa: PT011
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): # noqa: PT011
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): # noqa: PT011
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): # noqa: PT011
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): # noqa: PT011
6666
setup_profiler(make_options(mode))
6767

6868

0 commit comments

Comments
 (0)