Skip to content

Commit 469433d

Browse files
Close provider in try/finally in usage tests
The nullable-usage unit tests closed the provider after the assertions, so a failing assert would skip aclose() and leak the httpx client. Wrap embed() in try/finally to match the sibling tests.
1 parent c959e2d commit 469433d

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

tests/unit/test_retrieval_provider.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,10 @@ def handler(_req: httpx.Request) -> httpx.Response:
541541
return httpx.Response(200, json=body)
542542

543543
provider = _openai_embed_provider(handler)
544-
response = await provider.embed(["alpha string"])
545-
await provider.aclose()
544+
try:
545+
response = await provider.embed(["alpha string"])
546+
finally:
547+
await provider.aclose()
546548

547549
# No usage object on the wire -> no record. The vectors are unaffected.
548550
assert response.usage is None
@@ -565,8 +567,10 @@ def handler(_req: httpx.Request) -> httpx.Response:
565567
return httpx.Response(200, json=body)
566568

567569
provider = _openai_embed_provider(handler)
568-
response = await provider.embed(["alpha string"])
569-
await provider.aclose()
570+
try:
571+
response = await provider.embed(["alpha string"])
572+
finally:
573+
await provider.aclose()
570574

571575
# A corrupt figure reads as "not reported" rather than failing the call:
572576
# the embed succeeded and the vectors are sound, so a bad secondary
@@ -587,8 +591,10 @@ def handler(_req: httpx.Request) -> httpx.Response:
587591
)
588592

589593
provider = _openai_embed_provider(handler)
590-
response = await provider.embed(["alpha string"])
591-
await provider.aclose()
594+
try:
595+
response = await provider.embed(["alpha string"])
596+
finally:
597+
await provider.aclose()
592598

593599
# A REPORTED zero is a claim the provider actually made -- distinct from an
594600
# absent figure. It yields a record carrying 0, NOT usage = null.

0 commit comments

Comments
 (0)