Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ select = [
# 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
"T20", # print() and pprint() calls
"PT012", # pytest.raises() block with more than one statement
]

# Use ONLY the same ignores as the original flake8 config + compatibility for this codebase
Expand Down
18 changes: 9 additions & 9 deletions tests/integrations/anthropic/test_anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2074,7 +2074,7 @@ def test_streaming_create_message_api_error(
if span_streaming:
items = capture_items("transaction", "span")

with pytest.raises(APIStatusError), mock.patch.object(
with pytest.raises(APIStatusError), mock.patch.object( # noqa: PT012
client._client,
"send",
return_value=response,
Expand Down Expand Up @@ -2121,7 +2121,7 @@ def test_streaming_create_message_api_error(
elif stream_gen_ai_spans:
items = capture_items("transaction", "span")

with pytest.raises(APIStatusError), mock.patch.object(
with pytest.raises(APIStatusError), mock.patch.object( # noqa: PT012
client._client,
"send",
return_value=response,
Expand Down Expand Up @@ -2169,7 +2169,7 @@ def test_streaming_create_message_api_error(
else:
events = capture_events()

with pytest.raises(APIStatusError), mock.patch.object(
with pytest.raises(APIStatusError), mock.patch.object( # noqa: PT012
client._client,
"send",
return_value=response,
Expand Down Expand Up @@ -3617,7 +3617,7 @@ async def test_streaming_create_message_async_api_error(
if span_streaming:
items = capture_items("transaction", "span")

with pytest.raises(APIStatusError), mock.patch.object(
with pytest.raises(APIStatusError), mock.patch.object( # noqa: PT012
client._client,
"send",
return_value=response,
Expand Down Expand Up @@ -3664,7 +3664,7 @@ async def test_streaming_create_message_async_api_error(
elif stream_gen_ai_spans:
items = capture_items("transaction", "span")

with pytest.raises(APIStatusError), mock.patch.object(
with pytest.raises(APIStatusError), mock.patch.object( # noqa: PT012
client._client,
"send",
return_value=response,
Expand Down Expand Up @@ -3713,7 +3713,7 @@ async def test_streaming_create_message_async_api_error(
else:
events = capture_events()

with pytest.raises(APIStatusError), mock.patch.object(
with pytest.raises(APIStatusError), mock.patch.object( # noqa: PT012
client._client,
"send",
return_value=response,
Expand Down Expand Up @@ -4206,7 +4206,7 @@ async def test_stream_messages_async_api_error(
if span_streaming:
items = capture_items("transaction", "span")

with pytest.raises(APIStatusError), mock.patch.object(
with pytest.raises(APIStatusError), mock.patch.object( # noqa: PT012
client._client,
"send",
return_value=response,
Expand Down Expand Up @@ -4253,7 +4253,7 @@ async def test_stream_messages_async_api_error(
elif stream_gen_ai_spans:
items = capture_items("transaction", "span")

with pytest.raises(APIStatusError), mock.patch.object(
with pytest.raises(APIStatusError), mock.patch.object( # noqa: PT012
client._client,
"send",
return_value=response,
Expand Down Expand Up @@ -4299,7 +4299,7 @@ async def test_stream_messages_async_api_error(
else:
events = capture_events()

with pytest.raises(APIStatusError), mock.patch.object(
with pytest.raises(APIStatusError), mock.patch.object( # noqa: PT012
client._client,
"send",
return_value=response,
Expand Down
12 changes: 6 additions & 6 deletions tests/integrations/asgi/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ async def test_has_trace_if_performance_enabled(
)
app = SentryAsgiMiddleware(asgi3_app_with_error_and_msg)

with pytest.raises(ZeroDivisionError):
with pytest.raises(ZeroDivisionError): # noqa: PT012
async with TestClient(app) as client:
if span_streaming:
items = capture_items("event", "span")
Expand Down Expand Up @@ -418,7 +418,7 @@ async def test_has_trace_if_performance_disabled(
sentry_init()
app = SentryAsgiMiddleware(asgi3_app_with_error_and_msg)

with pytest.raises(ZeroDivisionError):
with pytest.raises(ZeroDivisionError): # noqa: PT012
async with TestClient(app) as client:
events = capture_events()
await client.get("/")
Expand Down Expand Up @@ -453,7 +453,7 @@ async def test_trace_from_headers_if_performance_enabled(
trace_id = "582b43a4192642f0b136d5159a501701"
sentry_trace_header = "{}-{}-{}".format(trace_id, "6e8f22c393e68f19", 1)

with pytest.raises(ZeroDivisionError):
with pytest.raises(ZeroDivisionError): # noqa: PT012
async with TestClient(app) as client:
if span_streaming:
items = capture_items("event", "span")
Expand Down Expand Up @@ -513,7 +513,7 @@ async def test_trace_from_headers_if_performance_disabled(
trace_id = "582b43a4192642f0b136d5159a501701"
sentry_trace_header = "{}-{}-{}".format(trace_id, "6e8f22c393e68f19", 1)

with pytest.raises(ZeroDivisionError):
with pytest.raises(ZeroDivisionError): # noqa: PT012
async with TestClient(app) as client:
events = capture_events()
await client.get("/", headers={"sentry-trace": sentry_trace_header})
Expand Down Expand Up @@ -552,7 +552,7 @@ async def test_websocket(

request_url = "/ws"

with pytest.raises(ValueError):
with pytest.raises(ValueError): # noqa: PT012
client = TestClient(asgi3_ws_app)
if span_streaming:
items = capture_items("event", "span")
Expand Down Expand Up @@ -609,7 +609,7 @@ async def test_auto_session_tracking_with_aggregates(
"endpoint": asgi3_app,
"client": ("127.0.0.1", 60457),
}
with pytest.raises(ZeroDivisionError):
with pytest.raises(ZeroDivisionError): # noqa: PT012
envelopes = capture_envelopes()
async with TestClient(app, scope=scope) as client:
scope["route"] = "/some/fine/url"
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/bottle/test_bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def index():

client = get_client()

with pytest.raises(ZeroDivisionError):
with pytest.raises(ZeroDivisionError): # noqa: PT012
try:
client.get("/")
except ZeroDivisionError as e:
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/django/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ def test_sql_psycopg2_placeholders(
items = capture_items("event")
sentry_sdk.get_isolation_scope().clear_breadcrumbs()

with pytest.raises(DataError):
with pytest.raises(DataError): # noqa: PT012
names = ["foo", "bar"]
identifiers = [psycopg2.sql.Identifier(name) for name in names]
placeholders = [
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/flask/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ def test_tracing_error(sentry_init, capture_events, capture_items, app, span_str
def error():
1 / 0

with pytest.raises(ZeroDivisionError):
with pytest.raises(ZeroDivisionError): # noqa: PT012
with app.test_client() as client:
response = client.get("/error")
assert response.status_code == 500
Expand Down Expand Up @@ -960,7 +960,7 @@ def test_error_has_trace_context_if_tracing_disabled(sentry_init, capture_events
def error():
1 / 0

with pytest.raises(ZeroDivisionError):
with pytest.raises(ZeroDivisionError): # noqa: PT012
with app.test_client() as client:
response = client.get("/error")
assert response.status_code == 500
Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/langgraph/test_langgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def original_invoke(self, *args, **kwargs):
if span_streaming or stream_gen_ai_spans:
items = capture_items("span")

with start_transaction(), pytest.raises(
with start_transaction(), pytest.raises( # noqa: PT012
Exception, match="Graph execution failed"
):
wrapped_invoke = _wrap_pregel_invoke(original_invoke)
Expand All @@ -634,7 +634,7 @@ def original_invoke(self, *args, **kwargs):
else:
events = capture_events()

with start_transaction(), pytest.raises(
with start_transaction(), pytest.raises( # noqa: PT012
Exception, match="Graph execution failed"
):
wrapped_invoke = _wrap_pregel_invoke(original_invoke)
Expand Down Expand Up @@ -676,7 +676,7 @@ async def original_ainvoke(self, *args, **kwargs):
raise Exception("Async graph execution failed")

async def run_error_test():
with start_transaction(), pytest.raises(
with start_transaction(), pytest.raises( # noqa: PT012
Exception, match="Async graph execution failed"
):
wrapped_ainvoke = _wrap_pregel_ainvoke(original_ainvoke)
Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/openai_agents/test_openai_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -4994,7 +4994,7 @@ async def test_run_streamed_error_handling(

items = capture_items("event", "span")

with pytest.raises(Exception, match="Model Error"):
with pytest.raises(Exception, match="Model Error"): # noqa: PT012
result = agents.Runner.run_streamed(
test_agent, "Test input", run_config=test_run_config
)
Expand Down Expand Up @@ -5034,7 +5034,7 @@ async def test_run_streamed_error_handling(

items = capture_items("event", "span", "transaction")

with pytest.raises(Exception, match="Model Error"):
with pytest.raises(Exception, match="Model Error"): # noqa: PT012
result = agents.Runner.run_streamed(
test_agent, "Test input", run_config=test_run_config
)
Expand Down Expand Up @@ -5074,7 +5074,7 @@ async def test_run_streamed_error_handling(
)
events = capture_events()

with pytest.raises(Exception, match="Model Error"):
with pytest.raises(Exception, match="Model Error"): # noqa: PT012
result = agents.Runner.run_streamed(
test_agent, "Test input", run_config=test_run_config
)
Expand Down
8 changes: 4 additions & 4 deletions tests/integrations/ray/test_ray.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,12 @@ def example_task():
with sentry_sdk.traces.start_span(
name="ray test parent", attributes={"sentry.op": "task"}
):
with pytest.raises(ZeroDivisionError):
with pytest.raises(ZeroDivisionError): # noqa: PT012
future = example_task.remote()
ray.get(future)
else:
with sentry_sdk.start_transaction(op="task", name="ray test transaction"):
with pytest.raises(ZeroDivisionError):
with pytest.raises(ZeroDivisionError): # noqa: PT012
future = example_task.remote()
ray.get(future)

Expand Down Expand Up @@ -530,13 +530,13 @@ def increment(self):
with sentry_sdk.traces.start_span(
name="ray test parent", attributes={"sentry.op": "task"}
):
with pytest.raises(ZeroDivisionError):
with pytest.raises(ZeroDivisionError): # noqa: PT012
counter = Counter.remote()
future = counter.increment.remote()
ray.get(future)
else:
with sentry_sdk.start_transaction(op="task", name="ray test transaction"):
with pytest.raises(ZeroDivisionError):
with pytest.raises(ZeroDivisionError): # noqa: PT012
counter = Counter.remote()
future = counter.increment.remote()
ray.get(future)
Expand Down
8 changes: 4 additions & 4 deletions tests/integrations/sqlalchemy/test_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class Address(Base):
session.query(Person).first()

for _ in range(2):
with pytest.raises(IntegrityError):
with pytest.raises(IntegrityError): # noqa: PT012
with session.begin_nested():
session.add(Person(id=1, name="bob"))
session.add(Person(id=1, name="bob"))
Expand Down Expand Up @@ -185,7 +185,7 @@ class Address(Base):
session.query(Person).first()

for _ in range(2):
with pytest.raises(IntegrityError):
with pytest.raises(IntegrityError): # noqa: PT012
with session.begin_nested():
session.add(Person(id=1, name="bob"))
session.add(Person(id=1, name="bob"))
Expand Down Expand Up @@ -270,7 +270,7 @@ class Address(Base):
session.query(Person).first()

for _ in range(2):
with pytest.raises(IntegrityError):
with pytest.raises(IntegrityError): # noqa: PT012
with session.begin_nested():
session.add(Person(id=1, name="bob"))
session.add(Person(id=1, name="bob"))
Expand All @@ -297,7 +297,7 @@ class Address(Base):
session.query(Person).first()

for _ in range(2):
with pytest.raises(IntegrityError):
with pytest.raises(IntegrityError): # noqa: PT012
with session.begin_nested():
session.add(Person(id=1, name="bob"))
session.add(Person(id=1, name="bob"))
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/stdlib/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ def test_http_timeout(
if span_streaming:
items = capture_items("span")

with pytest.raises(TimeoutError):
with pytest.raises(TimeoutError): # noqa: PT012
with sentry_sdk.traces.start_span(
name="name",
attributes={
Expand All @@ -1344,7 +1344,7 @@ def test_http_timeout(
else:
envelopes = capture_envelopes()

with pytest.raises(TimeoutError):
with pytest.raises(TimeoutError): # noqa: PT012
with start_transaction(op="op", name="name"):
conn = HTTPConnection("localhost", port=PORT)
conn.request("GET", "/bla")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: PT012
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: PT012
exc_value.detail = error
raise Exception
assert get_error_message(exc_value) == expected_result(exc_value)
Expand Down
4 changes: 2 additions & 2 deletions tests/tracing/test_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ def test_good_sysexit_doesnt_fail_transaction(

with start_transaction(name="hi") as transaction:
transaction.set_status(SPANSTATUS.OK)
with pytest.raises(SystemExit):
with pytest.raises(SystemExit): # noqa: PT012
with start_span(op="foo", name="foodesc"):
if exception_value is not False:
sys.exit(exception_value)
Expand All @@ -746,7 +746,7 @@ def test_good_sysexit_doesnt_fail_segment_span_streaming(
items = capture_items()

with sentry_sdk.traces.start_span(name="hi"):
with pytest.raises(SystemExit):
with pytest.raises(SystemExit): # noqa: PT012
with sentry_sdk.traces.start_span(name="foo"):
if exception_value is not False:
sys.exit(exception_value)
Expand Down
Loading