Skip to content

Commit e540bd6

Browse files
test: Fix tests that could not fail (#8288)
Fixes tests that [falsegreen](https://github.com/vinicq/falsegreen) flagged and that would keep passing even if the behavior they check broke. Test-only change. - `beam/test_beam.py::test_monkey_patch_signature`: the signature assert sat in `try/except Exception: pass` (a py2.7 leftover), so the `AssertionError` was swallowed. Removed the try. - `pydantic_ai/test_pydantic_ai.py::test_tool_execution_without_span_context`: `agent.run` was wrapped in `except Exception: pass` and followed by `assert True`. The run succeeds with the `test` model, so it now asserts on the result. - `test_envelope.py::test_add_and_get_session`: the assert sat inside `for`/`if`, so a missing session item passed. It now unpacks exactly one session item. - `grpc/test_grpc.py` and `grpc/test_grpc_aio.py::test_stream_stream`: an empty response stream passed. They now compare the collected responses. - `mcp/test_mcp.py::test_integration_patches_server`: on MCP v2 the whole body was skipped behind `if not IS_MCP_V2`, so it passed without running. It's now `skipif`. - Dropped duplicate parametrize cases in `test_utils.py::test_check_minimum_version` and `test_client.py::test_init_string_types`. <!-- junior-request-attribution:start --> via @sentrivana. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CAA8NNBE3%3A1794392136.309249 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Ivana Kellyer <131587164+sentrivana@users.noreply.github.com>
1 parent 4c1a136 commit e540bd6

8 files changed

Lines changed: 25 additions & 52 deletions

File tree

‎tests/integrations/beam/test_beam.py‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,13 @@ def test_monkey_patch_signature(f, args, kwargs):
140140
except Exception:
141141
print("Failed on {} with parameters {}, {}".format(f_temp, args, kwargs))
142142
raise
143-
try:
144-
expected_signature = inspect.signature(f)
145-
test_signature = inspect.signature(f_temp)
146-
assert expected_signature == test_signature, (
147-
"Failed on {}, signature {} does not match {}".format(
148-
f, expected_signature, test_signature
149-
)
143+
expected_signature = inspect.signature(f)
144+
test_signature = inspect.signature(f_temp)
145+
assert expected_signature == test_signature, (
146+
"Failed on {}, signature {} does not match {}".format(
147+
f, expected_signature, test_signature
150148
)
151-
except Exception:
152-
# expected to pass for py2.7
153-
pass
149+
)
154150

155151

156152
class _OutputHandler(OutputHandler):

‎tests/integrations/grpc/test_grpc.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,7 @@ def test_stream_stream(sentry_init):
666666
# Use the provided channel
667667
stub = gRPCTestServiceStub(channel)
668668
response_iterator = stub.TestStreamStream(iter((gRPCTestMessage(text="test"),)))
669-
for response in response_iterator:
670-
assert response.text == "test"
669+
assert [response.text for response in response_iterator] == ["test"]
671670

672671
_tear_down(server=server)
673672

‎tests/integrations/grpc/test_grpc_aio.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,7 @@ async def test_stream_stream(grpc_server_and_channel):
453453
# Use the provided channel
454454
stub = gRPCTestServiceStub(channel)
455455
response = stub.TestStreamStream((gRPCTestMessage(text="test"),))
456-
async for r in response:
457-
assert r.text == "test"
456+
assert [r.text async for r in response] == ["test"]
458457

459458

460459
@pytest.mark.asyncio

‎tests/integrations/mcp/test_mcp.py‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,21 @@ def __init__(self, text):
142142
self.text = text
143143

144144

145+
@pytest.mark.skipif(IS_MCP_V2, reason="Server decorator patching is MCP v1 only")
145146
def test_integration_patches_server(sentry_init):
146147
"""Test that MCPIntegration patches the Server class"""
147-
if not IS_MCP_V2:
148-
original_call_tool = Server.call_tool
149-
original_get_prompt = Server.get_prompt
150-
original_read_resource = Server.read_resource
148+
original_call_tool = Server.call_tool
149+
original_get_prompt = Server.get_prompt
150+
original_read_resource = Server.read_resource
151151

152-
sentry_init(
153-
integrations=[MCPIntegration()],
154-
traces_sample_rate=1.0,
155-
)
152+
sentry_init(
153+
integrations=[MCPIntegration()],
154+
traces_sample_rate=1.0,
155+
)
156156

157-
assert Server.call_tool is not original_call_tool
158-
assert Server.get_prompt is not original_get_prompt
159-
assert Server.read_resource is not original_read_resource
157+
assert Server.call_tool is not original_call_tool
158+
assert Server.get_prompt is not original_get_prompt
159+
assert Server.read_resource is not original_read_resource
160160

161161

162162
@pytest.mark.asyncio

‎tests/integrations/pydantic_ai/test_pydantic_ai.py‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3591,15 +3591,8 @@ async def test_tool_execution_without_span_context(sentry_init, capture_items):
35913591

35923592
# Call without span context (no transaction active)
35933593
# The patches should handle this gracefully
3594-
try:
3595-
# This will fail because we're not in a transaction, but it should not crash
3596-
await agent.run("test")
3597-
except Exception:
3598-
# Expected to fail, that's okay
3599-
pass
3600-
3601-
# Should not crash
3602-
assert True
3594+
result = await agent.run("test")
3595+
assert result.output is not None
36033596

36043597

36053598
@pytest.mark.asyncio

‎tests/test_client.py‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,20 +1038,8 @@ def custom_repr(value):
10381038
assert "Fail object" in my_vars["fail"]
10391039

10401040

1041-
@pytest.mark.parametrize(
1042-
"dsn",
1043-
[
1044-
"http://894b7d594095440f8dfea9b300e6f572@localhost:8000/2",
1045-
"http://894b7d594095440f8dfea9b300e6f572@localhost:8000/2",
1046-
],
1047-
)
1048-
def test_init_string_types(dsn, sentry_init):
1049-
# Allow unicode strings on Python 3 and both on Python 2 (due to
1050-
# unicode_literals)
1051-
#
1052-
# Supporting bytes on Python 3 is not really wrong but probably would be
1053-
# extra code
1054-
sentry_init(dsn)
1041+
def test_init_string_types(sentry_init):
1042+
sentry_init("http://894b7d594095440f8dfea9b300e6f572@localhost:8000/2")
10551043
assert (
10561044
sentry_sdk.get_client().dsn
10571045
== "http://894b7d594095440f8dfea9b300e6f572@localhost:8000/2"

‎tests/test_envelope.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ def test_add_and_get_session():
7373
expected = Session()
7474
envelope.add_session(expected)
7575

76-
for item in envelope:
77-
if item.type == "session":
78-
assert item.payload.json == expected.to_json()
76+
(item,) = [item for item in envelope if item.type == "session"]
77+
assert item.payload.json == expected.to_json()
7978

8079

8180
def test_envelope_headers(sentry_init, capture_envelopes, monkeypatch):

‎tests/test_utils.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,6 @@ def test_parse_version(version, expected_result):
835835
),
836836
False,
837837
),
838-
("1.0.1", (2, 0, 0), False),
839838
("2.0", (1,), True),
840839
(
841840
"2.0.1",

0 commit comments

Comments
 (0)