Skip to content

Commit 5f94399

Browse files
committed
Fix some instances of PT012 pytest-raises-with-multiple-statements
1 parent 1630b73 commit 5f94399

7 files changed

+113
-113
lines changed

tests/mlmodel_langchain/test_vectorstore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ def test_vectorstore_error(set_trace_info, embedding_openai_client, loop):
371371
)
372372
@background_task()
373373
def test_vectorstore_error_no_content(set_trace_info, embedding_openai_client):
374+
set_trace_info()
374375
with pytest.raises(AssertionError):
375-
set_trace_info()
376376
script_dir = os.path.dirname(__file__)
377377
loader = PyPDFLoader(os.path.join(script_dir, "hello.pdf"))
378378
docs = loader.load()

tests/mlmodel_openai/test_chat_completion_error.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@
112112
@validate_custom_event_count(count=3)
113113
@background_task()
114114
def test_chat_completion_invalid_request_error_no_model(set_trace_info):
115+
set_trace_info()
115116
with pytest.raises(openai.InvalidRequestError):
116-
set_trace_info()
117117
add_custom_attribute("llm.conversation_id", "my-awesome-id")
118118
with WithLlmCustomAttributes({"context": "attr"}):
119119
openai.ChatCompletion.create(
@@ -146,8 +146,8 @@ def test_chat_completion_invalid_request_error_no_model(set_trace_info):
146146
@validate_custom_event_count(count=3)
147147
@background_task()
148148
def test_chat_completion_invalid_request_error_no_model_no_content(set_trace_info):
149+
set_trace_info()
149150
with pytest.raises(openai.InvalidRequestError):
150-
set_trace_info()
151151
add_custom_attribute("llm.conversation_id", "my-awesome-id")
152152
openai.ChatCompletion.create(
153153
# no model provided,
@@ -211,8 +211,8 @@ def test_chat_completion_invalid_request_error_no_model_no_content(set_trace_inf
211211
@validate_custom_event_count(count=2)
212212
@background_task()
213213
def test_chat_completion_invalid_request_error_invalid_model_with_token_count(set_trace_info):
214+
set_trace_info()
214215
with pytest.raises(openai.InvalidRequestError):
215-
set_trace_info()
216216
add_custom_attribute("llm.conversation_id", "my-awesome-id")
217217

218218
openai.ChatCompletion.create(
@@ -241,8 +241,8 @@ def test_chat_completion_invalid_request_error_invalid_model_with_token_count(se
241241
@validate_custom_event_count(count=2)
242242
@background_task()
243243
def test_chat_completion_invalid_request_error_invalid_model(set_trace_info):
244+
set_trace_info()
244245
with pytest.raises(openai.InvalidRequestError):
245-
set_trace_info()
246246
add_custom_attribute("llm.conversation_id", "my-awesome-id")
247247
openai.ChatCompletion.create(
248248
model="does-not-exist",
@@ -324,8 +324,8 @@ def test_chat_completion_invalid_request_error_invalid_model(set_trace_info):
324324
@validate_custom_event_count(count=3)
325325
@background_task()
326326
def test_chat_completion_authentication_error(monkeypatch, set_trace_info):
327+
set_trace_info()
327328
with pytest.raises(openai.error.AuthenticationError):
328-
set_trace_info()
329329
add_custom_attribute("llm.conversation_id", "my-awesome-id")
330330
monkeypatch.setattr(openai, "api_key", None) # openai.api_key = None
331331
openai.ChatCompletion.create(
@@ -389,9 +389,9 @@ def test_chat_completion_authentication_error(monkeypatch, set_trace_info):
389389
@validate_custom_event_count(count=2)
390390
@background_task()
391391
def test_chat_completion_wrong_api_key_error(monkeypatch, set_trace_info):
392+
set_trace_info()
393+
monkeypatch.setattr(openai, "api_key", "DEADBEEF") # openai.api_key = "DEADBEEF"
392394
with pytest.raises(openai.error.AuthenticationError):
393-
set_trace_info()
394-
monkeypatch.setattr(openai, "api_key", "DEADBEEF") # openai.api_key = "DEADBEEF"
395395
openai.ChatCompletion.create(
396396
model="gpt-3.5-turbo",
397397
messages=({"role": "user", "content": "Invalid API key."},),
@@ -423,8 +423,8 @@ def test_chat_completion_wrong_api_key_error(monkeypatch, set_trace_info):
423423
@validate_custom_event_count(count=3)
424424
@background_task()
425425
def test_chat_completion_invalid_request_error_no_model_async(loop, set_trace_info):
426+
set_trace_info()
426427
with pytest.raises(openai.InvalidRequestError):
427-
set_trace_info()
428428
add_custom_attribute("llm.conversation_id", "my-awesome-id")
429429
loop.run_until_complete(
430430
openai.ChatCompletion.acreate(
@@ -458,8 +458,8 @@ def test_chat_completion_invalid_request_error_no_model_async(loop, set_trace_in
458458
@validate_custom_event_count(count=3)
459459
@background_task()
460460
def test_chat_completion_invalid_request_error_no_model_async_no_content(loop, set_trace_info):
461+
set_trace_info()
461462
with pytest.raises(openai.InvalidRequestError):
462-
set_trace_info()
463463
add_custom_attribute("llm.conversation_id", "my-awesome-id")
464464
loop.run_until_complete(
465465
openai.ChatCompletion.acreate(
@@ -489,8 +489,8 @@ def test_chat_completion_invalid_request_error_no_model_async_no_content(loop, s
489489
@validate_custom_event_count(count=2)
490490
@background_task()
491491
def test_chat_completion_invalid_request_error_invalid_model_with_token_count_async(loop, set_trace_info):
492+
set_trace_info()
492493
with pytest.raises(openai.InvalidRequestError):
493-
set_trace_info()
494494
add_custom_attribute("llm.conversation_id", "my-awesome-id")
495495
loop.run_until_complete(
496496
openai.ChatCompletion.acreate(
@@ -520,8 +520,8 @@ def test_chat_completion_invalid_request_error_invalid_model_with_token_count_as
520520
@validate_custom_event_count(count=2)
521521
@background_task()
522522
def test_chat_completion_invalid_request_error_invalid_model_async(loop, set_trace_info):
523+
set_trace_info()
523524
with pytest.raises(openai.InvalidRequestError):
524-
set_trace_info()
525525
add_custom_attribute("llm.conversation_id", "my-awesome-id")
526526
loop.run_until_complete(
527527
openai.ChatCompletion.acreate(
@@ -554,8 +554,8 @@ def test_chat_completion_invalid_request_error_invalid_model_async(loop, set_tra
554554
@validate_custom_event_count(count=3)
555555
@background_task()
556556
def test_chat_completion_authentication_error_async(loop, monkeypatch, set_trace_info):
557+
set_trace_info()
557558
with pytest.raises(openai.error.AuthenticationError):
558-
set_trace_info()
559559
add_custom_attribute("llm.conversation_id", "my-awesome-id")
560560
monkeypatch.setattr(openai, "api_key", None) # openai.api_key = None
561561
loop.run_until_complete(
@@ -587,9 +587,9 @@ def test_chat_completion_authentication_error_async(loop, monkeypatch, set_trace
587587
@validate_custom_event_count(count=2)
588588
@background_task()
589589
def test_chat_completion_wrong_api_key_error_async(loop, monkeypatch, set_trace_info):
590+
set_trace_info()
591+
monkeypatch.setattr(openai, "api_key", "DEADBEEF") # openai.api_key = "DEADBEEF"
590592
with pytest.raises(openai.error.AuthenticationError):
591-
set_trace_info()
592-
monkeypatch.setattr(openai, "api_key", "DEADBEEF") # openai.api_key = "DEADBEEF"
593593
loop.run_until_complete(
594594
openai.ChatCompletion.acreate(
595595
model="gpt-3.5-turbo",

tests/mlmodel_openai/test_chat_completion_error_v1.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@
107107
@validate_custom_event_count(count=3)
108108
@background_task()
109109
def test_chat_completion_invalid_request_error_no_model(set_trace_info, sync_openai_client):
110+
set_trace_info()
110111
with pytest.raises(TypeError):
111-
set_trace_info()
112112
add_custom_attribute("llm.conversation_id", "my-awesome-id")
113113
with WithLlmCustomAttributes({"context": "attr"}):
114114
sync_openai_client.chat.completions.create(
@@ -134,8 +134,8 @@ def test_chat_completion_invalid_request_error_no_model(set_trace_info, sync_ope
134134
@validate_custom_event_count(count=3)
135135
@background_task()
136136
def test_chat_completion_invalid_request_error_no_model_no_content(set_trace_info, sync_openai_client):
137+
set_trace_info()
137138
with pytest.raises(TypeError):
138-
set_trace_info()
139139
add_custom_attribute("llm.conversation_id", "my-awesome-id")
140140
sync_openai_client.chat.completions.create(
141141
messages=_test_openai_chat_completion_messages, temperature=0.7, max_tokens=100
@@ -160,8 +160,8 @@ def test_chat_completion_invalid_request_error_no_model_no_content(set_trace_inf
160160
@validate_custom_event_count(count=3)
161161
@background_task()
162162
def test_chat_completion_invalid_request_error_no_model_async(loop, set_trace_info, async_openai_client):
163+
set_trace_info()
163164
with pytest.raises(TypeError):
164-
set_trace_info()
165165
add_custom_attribute("llm.conversation_id", "my-awesome-id")
166166

167167
with WithLlmCustomAttributes({"context": "attr"}):
@@ -190,8 +190,8 @@ def test_chat_completion_invalid_request_error_no_model_async(loop, set_trace_in
190190
@validate_custom_event_count(count=3)
191191
@background_task()
192192
def test_chat_completion_invalid_request_error_no_model_async_no_content(loop, set_trace_info, async_openai_client):
193+
set_trace_info()
193194
with pytest.raises(TypeError):
194-
set_trace_info()
195195
add_custom_attribute("llm.conversation_id", "my-awesome-id")
196196
loop.run_until_complete(
197197
async_openai_client.chat.completions.create(
@@ -255,8 +255,8 @@ def test_chat_completion_invalid_request_error_no_model_async_no_content(loop, s
255255
@validate_custom_event_count(count=2)
256256
@background_task()
257257
def test_chat_completion_invalid_request_error_invalid_model(set_trace_info, sync_openai_client):
258+
set_trace_info()
258259
with pytest.raises(openai.NotFoundError):
259-
set_trace_info()
260260
add_custom_attribute("llm.conversation_id", "my-awesome-id")
261261
sync_openai_client.chat.completions.create(
262262
model="does-not-exist",
@@ -286,8 +286,8 @@ def test_chat_completion_invalid_request_error_invalid_model(set_trace_info, syn
286286
@validate_custom_event_count(count=2)
287287
@background_task()
288288
def test_chat_completion_invalid_request_error_invalid_model_with_token_count(set_trace_info, sync_openai_client):
289+
set_trace_info()
289290
with pytest.raises(openai.NotFoundError):
290-
set_trace_info()
291291
add_custom_attribute("llm.conversation_id", "my-awesome-id")
292292
sync_openai_client.chat.completions.create(
293293
model="does-not-exist",
@@ -316,8 +316,8 @@ def test_chat_completion_invalid_request_error_invalid_model_with_token_count(se
316316
@validate_custom_event_count(count=2)
317317
@background_task()
318318
def test_chat_completion_invalid_request_error_invalid_model_async(loop, set_trace_info, async_openai_client):
319+
set_trace_info()
319320
with pytest.raises(openai.NotFoundError):
320-
set_trace_info()
321321
add_custom_attribute("llm.conversation_id", "my-awesome-id")
322322
loop.run_until_complete(
323323
async_openai_client.chat.completions.create(
@@ -351,8 +351,8 @@ def test_chat_completion_invalid_request_error_invalid_model_async(loop, set_tra
351351
def test_chat_completion_invalid_request_error_invalid_model_with_token_count_async(
352352
loop, set_trace_info, async_openai_client
353353
):
354+
set_trace_info()
354355
with pytest.raises(openai.NotFoundError):
355-
set_trace_info()
356356
add_custom_attribute("llm.conversation_id", "my-awesome-id")
357357
loop.run_until_complete(
358358
async_openai_client.chat.completions.create(
@@ -419,9 +419,9 @@ def test_chat_completion_invalid_request_error_invalid_model_with_token_count_as
419419
@validate_custom_event_count(count=2)
420420
@background_task()
421421
def test_chat_completion_wrong_api_key_error(monkeypatch, set_trace_info, sync_openai_client):
422+
set_trace_info()
423+
monkeypatch.setattr(sync_openai_client, "api_key", "DEADBEEF")
422424
with pytest.raises(openai.AuthenticationError):
423-
set_trace_info()
424-
monkeypatch.setattr(sync_openai_client, "api_key", "DEADBEEF")
425425
sync_openai_client.chat.completions.create(
426426
model="gpt-3.5-turbo",
427427
messages=({"role": "user", "content": "Invalid API key."},),
@@ -451,9 +451,9 @@ def test_chat_completion_wrong_api_key_error(monkeypatch, set_trace_info, sync_o
451451
@validate_custom_event_count(count=2)
452452
@background_task()
453453
def test_chat_completion_wrong_api_key_error_async(loop, monkeypatch, set_trace_info, async_openai_client):
454+
set_trace_info()
455+
monkeypatch.setattr(async_openai_client, "api_key", "DEADBEEF")
454456
with pytest.raises(openai.AuthenticationError):
455-
set_trace_info()
456-
monkeypatch.setattr(async_openai_client, "api_key", "DEADBEEF")
457457
loop.run_until_complete(
458458
async_openai_client.chat.completions.create(
459459
model="gpt-3.5-turbo",
@@ -482,8 +482,8 @@ def test_chat_completion_wrong_api_key_error_async(loop, monkeypatch, set_trace_
482482
@validate_custom_event_count(count=3)
483483
@background_task()
484484
def test_chat_completion_invalid_request_error_no_model_with_raw_response(set_trace_info, sync_openai_client):
485+
set_trace_info()
485486
with pytest.raises(TypeError):
486-
set_trace_info()
487487
add_custom_attribute("llm.conversation_id", "my-awesome-id")
488488
sync_openai_client.chat.completions.with_raw_response.create(
489489
messages=_test_openai_chat_completion_messages, temperature=0.7, max_tokens=100
@@ -511,8 +511,8 @@ def test_chat_completion_invalid_request_error_no_model_with_raw_response(set_tr
511511
def test_chat_completion_invalid_request_error_no_model_no_content_with_raw_response(
512512
set_trace_info, sync_openai_client
513513
):
514+
set_trace_info()
514515
with pytest.raises(TypeError):
515-
set_trace_info()
516516
add_custom_attribute("llm.conversation_id", "my-awesome-id")
517517
sync_openai_client.chat.completions.with_raw_response.create(
518518
messages=_test_openai_chat_completion_messages, temperature=0.7, max_tokens=100
@@ -539,8 +539,8 @@ def test_chat_completion_invalid_request_error_no_model_no_content_with_raw_resp
539539
def test_chat_completion_invalid_request_error_no_model_async_with_raw_response(
540540
loop, set_trace_info, async_openai_client
541541
):
542+
set_trace_info()
542543
with pytest.raises(TypeError):
543-
set_trace_info()
544544
add_custom_attribute("llm.conversation_id", "my-awesome-id")
545545
loop.run_until_complete(
546546
async_openai_client.chat.completions.with_raw_response.create(
@@ -570,8 +570,8 @@ def test_chat_completion_invalid_request_error_no_model_async_with_raw_response(
570570
def test_chat_completion_invalid_request_error_no_model_async_no_content_with_raw_response(
571571
loop, set_trace_info, async_openai_client
572572
):
573+
set_trace_info()
573574
with pytest.raises(TypeError):
574-
set_trace_info()
575575
add_custom_attribute("llm.conversation_id", "my-awesome-id")
576576
loop.run_until_complete(
577577
async_openai_client.chat.completions.with_raw_response.create(
@@ -599,8 +599,8 @@ def test_chat_completion_invalid_request_error_no_model_async_no_content_with_ra
599599
@validate_custom_event_count(count=2)
600600
@background_task()
601601
def test_chat_completion_invalid_request_error_invalid_model_with_raw_response(set_trace_info, sync_openai_client):
602+
set_trace_info()
602603
with pytest.raises(openai.NotFoundError):
603-
set_trace_info()
604604
add_custom_attribute("llm.conversation_id", "my-awesome-id")
605605
sync_openai_client.chat.completions.with_raw_response.create(
606606
model="does-not-exist",
@@ -632,8 +632,8 @@ def test_chat_completion_invalid_request_error_invalid_model_with_raw_response(s
632632
def test_chat_completion_invalid_request_error_invalid_model_with_token_count_with_raw_response(
633633
set_trace_info, sync_openai_client
634634
):
635+
set_trace_info()
635636
with pytest.raises(openai.NotFoundError):
636-
set_trace_info()
637637
add_custom_attribute("llm.conversation_id", "my-awesome-id")
638638
sync_openai_client.chat.completions.with_raw_response.create(
639639
model="does-not-exist",
@@ -664,8 +664,8 @@ def test_chat_completion_invalid_request_error_invalid_model_with_token_count_wi
664664
def test_chat_completion_invalid_request_error_invalid_model_async_with_raw_response(
665665
loop, set_trace_info, async_openai_client
666666
):
667+
set_trace_info()
667668
with pytest.raises(openai.NotFoundError):
668-
set_trace_info()
669669
add_custom_attribute("llm.conversation_id", "my-awesome-id")
670670
loop.run_until_complete(
671671
async_openai_client.chat.completions.with_raw_response.create(
@@ -699,8 +699,8 @@ def test_chat_completion_invalid_request_error_invalid_model_async_with_raw_resp
699699
def test_chat_completion_invalid_request_error_invalid_model_with_token_count_async_with_raw_response(
700700
loop, set_trace_info, async_openai_client
701701
):
702+
set_trace_info()
702703
with pytest.raises(openai.NotFoundError):
703-
set_trace_info()
704704
add_custom_attribute("llm.conversation_id", "my-awesome-id")
705705
loop.run_until_complete(
706706
async_openai_client.chat.completions.with_raw_response.create(
@@ -733,9 +733,9 @@ def test_chat_completion_invalid_request_error_invalid_model_with_token_count_as
733733
@validate_custom_event_count(count=2)
734734
@background_task()
735735
def test_chat_completion_wrong_api_key_error_with_raw_response(monkeypatch, set_trace_info, sync_openai_client):
736+
set_trace_info()
737+
monkeypatch.setattr(sync_openai_client, "api_key", "DEADBEEF")
736738
with pytest.raises(openai.AuthenticationError):
737-
set_trace_info()
738-
monkeypatch.setattr(sync_openai_client, "api_key", "DEADBEEF")
739739
sync_openai_client.chat.completions.with_raw_response.create(
740740
model="gpt-3.5-turbo",
741741
messages=({"role": "user", "content": "Invalid API key."},),
@@ -767,9 +767,9 @@ def test_chat_completion_wrong_api_key_error_with_raw_response(monkeypatch, set_
767767
def test_chat_completion_wrong_api_key_error_async_with_raw_response(
768768
loop, monkeypatch, set_trace_info, async_openai_client
769769
):
770+
set_trace_info()
771+
monkeypatch.setattr(async_openai_client, "api_key", "DEADBEEF")
770772
with pytest.raises(openai.AuthenticationError):
771-
set_trace_info()
772-
monkeypatch.setattr(async_openai_client, "api_key", "DEADBEEF")
773773
loop.run_until_complete(
774774
async_openai_client.chat.completions.with_raw_response.create(
775775
model="gpt-3.5-turbo",

0 commit comments

Comments
 (0)