Skip to content

Commit 3b061d2

Browse files
authored
test: fix dead assert in retry streaming tests causing coverage issues (#17723)
## Problem In `test_retry_streaming.py` and `test_retry_streaming_async.py`, an assert statement was indented inside the `pytest.raises` context manager block. In Python testing with `pytest`, any code in a pytest.raises block that follows line that raises the expected exception is NOT executed. This meant that the assert statement intended to verify the exception message was dead code and never ran. ## Solution The assert statement has been dedented (moved outside and after the `pytest.raises` block) to ensure it executes after the exception is caught. This allows the test to actually verify the exception message as originally intended. ## Notes to Reviewers This fix ensures that the tests are actually checking that the exception contains the message "can't send non-None value". It also helps with code coverage metrics by removing dead code.
1 parent fcaad3c commit 3b061d2

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

packages/google-api-core/tests/asyncio/retry/test_retry_streaming_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ async def test___call___generator_send_retry(self, sleep):
293293
generator = await retry_(self._generator_mock)(error_on=3)
294294
with pytest.raises(TypeError) as exc_info:
295295
await generator.asend("cannot send to fresh generator")
296-
assert exc_info.match("can't send non-None value")
296+
assert exc_info.match("can't send non-None value")
297297
await generator.aclose()
298298

299299
# error thrown on 3

packages/google-api-core/tests/unit/retry/test_retry_streaming.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def test___call___with_generator_send_retry(self, sleep):
263263
with pytest.raises(TypeError) as exc_info:
264264
# calling first send with non-None input should raise a TypeError
265265
result.send("can not send to fresh generator")
266-
assert exc_info.match("can't send non-None value")
266+
assert exc_info.match("can't send non-None value")
267267
# initiate iteration with None
268268
result = retry_(self._generator_mock)(error_on=3)
269269
assert result.send(None) == 0

0 commit comments

Comments
 (0)