From cc9546b761ecd450fff6cc7cacdd96e4ca814c85 Mon Sep 17 00:00:00 2001 From: Jin Hai Date: Thu, 18 Dec 2025 11:27:02 +0800 Subject: [PATCH] Fix IDE warnings (#12010) ### What problem does this PR solve? As title ### Type of change - [x] Refactoring Signed-off-by: Jin Hai --- download_deps.py | 8 +-- test/testcases/conftest.py | 1 + .../test_create_chat_assistant.py | 20 +++--- .../test_delete_chat_assistants.py | 8 +-- .../test_list_chat_assistants.py | 28 ++++---- .../test_update_chat_assistant.py | 12 ++-- .../test_add_chunk.py | 16 ++--- .../test_delete_chunks.py | 12 ++-- .../test_list_chunks.py | 12 ++-- .../test_retrieval_chunks.py | 28 ++++---- .../test_update_chunk.py | 20 +++--- .../test_create_dataset.py | 56 +++++++-------- .../test_delete_datasets.py | 33 ++++----- .../test_list_datasets.py | 67 ++++++++--------- .../test_update_dataset.py | 72 +++++++++---------- .../test_delete_documents.py | 12 ++-- .../test_list_documents.py | 32 ++++----- .../test_parse_documents.py | 24 +++---- .../test_update_document.py | 20 +++--- .../test_upload_documents.py | 12 ++-- .../test_session_management/conftest.py | 7 +- ...test_create_session_with_chat_assistant.py | 8 +-- ...est_delete_sessions_with_chat_assistant.py | 8 +-- .../test_list_sessions_with_chat_assistant.py | 34 ++++----- ...test_update_session_with_chat_assistant.py | 12 ++-- 25 files changed, 283 insertions(+), 279 deletions(-) diff --git a/download_deps.py b/download_deps.py index 09966f377..a8dfbb476 100644 --- a/download_deps.py +++ b/download_deps.py @@ -49,10 +49,10 @@ repos = [ ] -def download_model(repo_id): - local_dir = os.path.abspath(os.path.join("huggingface.co", repo_id)) - os.makedirs(local_dir, exist_ok=True) - snapshot_download(repo_id=repo_id, local_dir=local_dir) +def download_model(repository_id): + local_directory = os.path.abspath(os.path.join("huggingface.co", repository_id)) + os.makedirs(local_directory, exist_ok=True) + snapshot_download(repo_id=repository_id, local_dir=local_directory) if __name__ == "__main__": diff --git a/test/testcases/conftest.py b/test/testcases/conftest.py index 1d9ed32f3..27826e125 100644 --- a/test/testcases/conftest.py +++ b/test/testcases/conftest.py @@ -131,6 +131,7 @@ def get_tenant_info(auth): @pytest.fixture(scope="session", autouse=True) def set_tenant_info(auth): + tenant_id = None try: add_models(auth) tenant_id = get_tenant_info(auth) diff --git a/test/testcases/test_sdk_api/test_chat_assistant_management/test_create_chat_assistant.py b/test/testcases/test_sdk_api/test_chat_assistant_management/test_create_chat_assistant.py index 1214bcc41..502a428e3 100644 --- a/test/testcases/test_sdk_api/test_chat_assistant_management/test_create_chat_assistant.py +++ b/test/testcases/test_sdk_api/test_chat_assistant_management/test_create_chat_assistant.py @@ -45,9 +45,9 @@ class TestChatAssistantCreate: client.create_chat(name=name.upper()) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_chat(name=name) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: chat_assistant = client.create_chat(name=name) assert chat_assistant.name == name @@ -68,9 +68,9 @@ class TestChatAssistantCreate: dataset_ids = dataset_ids(dataset.id) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_chat(name="ragflow test", dataset_ids=dataset_ids) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: chat_assistant = client.create_chat(name="ragflow test", dataset_ids=dataset_ids) assert chat_assistant.name == "ragflow test" @@ -121,9 +121,9 @@ class TestChatAssistantCreate: llm_o = Chat.LLM(client, llm) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_chat(name="llm_test", dataset_ids=[dataset.id], llm=llm_o) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: chat_assistant = client.create_chat(name="llm_test", dataset_ids=[dataset.id], llm=llm_o) if llm: @@ -189,9 +189,9 @@ class TestChatAssistantCreate: prompt_o = Chat.Prompt(client, prompt) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_chat(name="prompt_test", dataset_ids=[dataset.id], prompt=prompt_o) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: chat_assistant = client.create_chat(name="prompt_test", dataset_ids=[dataset.id], prompt=prompt_o) if prompt: @@ -219,6 +219,6 @@ class TestChatAssistantCreate2: @pytest.mark.p2 def test_unparsed_document(self, client, add_document): dataset, _ = add_document - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_chat(name="prompt_test", dataset_ids=[dataset.id]) - assert "doesn't own parsed file" in str(excinfo.value) + assert "doesn't own parsed file" in str(exception_info.value) diff --git a/test/testcases/test_sdk_api/test_chat_assistant_management/test_delete_chat_assistants.py b/test/testcases/test_sdk_api/test_chat_assistant_management/test_delete_chat_assistants.py index db0c39ff8..3d3be6f52 100644 --- a/test/testcases/test_sdk_api/test_chat_assistant_management/test_delete_chat_assistants.py +++ b/test/testcases/test_sdk_api/test_chat_assistant_management/test_delete_chat_assistants.py @@ -37,9 +37,9 @@ class TestChatAssistantsDelete: payload = payload([chat_assistant.id for chat_assistant in chat_assistants]) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.delete_chats(**payload) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: if payload is None: client.delete_chats(payload) @@ -71,9 +71,9 @@ class TestChatAssistantsDelete: chat_ids = [chat.id for chat in chat_assistants] client.delete_chats(ids=chat_ids) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.delete_chats(ids=chat_ids) - assert "not found" in str(excinfo.value) + assert "not found" in str(exception_info.value) @pytest.mark.p3 def test_duplicate_deletion(self, client, add_chat_assistants_func): diff --git a/test/testcases/test_sdk_api/test_chat_assistant_management/test_list_chat_assistants.py b/test/testcases/test_sdk_api/test_chat_assistant_management/test_list_chat_assistants.py index d79a4f55d..eb3b36288 100644 --- a/test/testcases/test_sdk_api/test_chat_assistant_management/test_list_chat_assistants.py +++ b/test/testcases/test_sdk_api/test_chat_assistant_management/test_list_chat_assistants.py @@ -49,9 +49,9 @@ class TestChatAssistantsList: ) def test_page(self, client, params, expected_page_size, expected_message): if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_chats(**params) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: assistants = client.list_chats(**params) assert len(assistants) == expected_page_size @@ -80,9 +80,9 @@ class TestChatAssistantsList: ) def test_page_size(self, client, params, expected_page_size, expected_message): if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_chats(**params) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: assistants = client.list_chats(**params) assert len(assistants) == expected_page_size @@ -99,9 +99,9 @@ class TestChatAssistantsList: ) def test_orderby(self, client, params, expected_message): if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_chats(**params) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: client.list_chats(**params) @@ -126,9 +126,9 @@ class TestChatAssistantsList: ) def test_desc(self, client, params, expected_message): if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_chats(**params) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: client.list_chats(**params) @@ -144,9 +144,9 @@ class TestChatAssistantsList: ) def test_name(self, client, params, expected_num, expected_message): if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_chats(**params) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: assistants = client.list_chats(**params) if params["name"] in [None, ""]: @@ -172,9 +172,9 @@ class TestChatAssistantsList: params = {"id": chat_assistant_id} if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_chats(**params) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: assistants = client.list_chats(**params) if params["id"] in [None, ""]: @@ -200,9 +200,9 @@ class TestChatAssistantsList: params = {"id": chat_assistant_id, "name": name} if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_chats(**params) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: assistants = client.list_chats(**params) assert len(assistants) == expected_num diff --git a/test/testcases/test_sdk_api/test_chat_assistant_management/test_update_chat_assistant.py b/test/testcases/test_sdk_api/test_chat_assistant_management/test_update_chat_assistant.py index bae5bb6bf..df32561cc 100644 --- a/test/testcases/test_sdk_api/test_chat_assistant_management/test_update_chat_assistant.py +++ b/test/testcases/test_sdk_api/test_chat_assistant_management/test_update_chat_assistant.py @@ -39,9 +39,9 @@ class TestChatAssistantUpdate: chat_assistant = chat_assistants[0] if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chat_assistant.update(payload) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: chat_assistant.update(payload) updated_chat = client.list_chats(id=chat_assistant.id)[0] @@ -101,9 +101,9 @@ class TestChatAssistantUpdate: payload = {"name": "llm_test", "llm": llm, "dataset_ids": [dataset.id]} if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chat_assistant.update(payload) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: chat_assistant.update(payload) updated_chat = client.list_chats(id=chat_assistant.id)[0] @@ -178,9 +178,9 @@ class TestChatAssistantUpdate: payload = {"name": "prompt_test", "prompt": prompt, "dataset_ids": [dataset.id]} if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chat_assistant.update(payload) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: chat_assistant.update(payload) updated_chat = client.list_chats(id=chat_assistant.id)[0] diff --git a/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_add_chunk.py b/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_add_chunk.py index 5d1638db2..fb6d17ed2 100644 --- a/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_add_chunk.py +++ b/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_add_chunk.py @@ -48,9 +48,9 @@ class TestAddChunk: chunks_count = len(document.list_chunks()) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: document.add_chunk(**payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunk = document.add_chunk(**payload) validate_chunk_details(dataset.id, document.id, payload, chunk) @@ -76,9 +76,9 @@ class TestAddChunk: chunks_count = len(document.list_chunks()) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: document.add_chunk(**payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunk = document.add_chunk(**payload) validate_chunk_details(dataset.id, document.id, payload, chunk) @@ -104,9 +104,9 @@ class TestAddChunk: chunks_count = len(document.list_chunks()) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: document.add_chunk(**payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunk = document.add_chunk(**payload) validate_chunk_details(dataset.id, document.id, payload, chunk) @@ -138,9 +138,9 @@ class TestAddChunk: dataset, document = add_document dataset.delete_documents(ids=[document.id]) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: document.add_chunk(content="chunk test") - assert f"You don't own the document {document.id}" in str(excinfo.value), str(excinfo.value) + assert f"You don't own the document {document.id}" in str(exception_info.value), str(exception_info.value) @pytest.mark.skip(reason="issues/6411") @pytest.mark.p3 diff --git a/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_delete_chunks.py b/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_delete_chunks.py index 25aac7b88..319dac0e8 100644 --- a/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_delete_chunks.py +++ b/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_delete_chunks.py @@ -33,9 +33,9 @@ class TestChunksDeletion: chunk_ids = [chunk.id for chunk in chunks] payload = payload(chunk_ids) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: document.delete_chunks(**payload) - assert "rm_chunk deleted chunks" in str(excinfo.value), str(excinfo.value) + assert "rm_chunk deleted chunks" in str(exception_info.value), str(exception_info.value) remaining_chunks = document.list_chunks() assert len(remaining_chunks) == 1, str(remaining_chunks) @@ -46,9 +46,9 @@ class TestChunksDeletion: chunk_ids = [chunk.id for chunk in chunks] document.delete_chunks(ids=chunk_ids) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: document.delete_chunks(ids=chunk_ids) - assert "rm_chunk deleted chunks 0, expect" in str(excinfo.value), str(excinfo.value) + assert "rm_chunk deleted chunks 0, expect" in str(exception_info.value), str(exception_info.value) @pytest.mark.p3 def test_duplicate_deletion(self, add_chunks_func): @@ -103,9 +103,9 @@ class TestChunksDeletion: payload = payload(chunk_ids) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: document.delete_chunks(**payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: document.delete_chunks(**payload) diff --git a/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_list_chunks.py b/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_list_chunks.py index d0d790320..e29378528 100644 --- a/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_list_chunks.py +++ b/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_list_chunks.py @@ -38,9 +38,9 @@ class TestChunksList: _, document, _ = add_chunks if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: document.list_chunks(**params) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunks = document.list_chunks(**params) assert len(chunks) == expected_page_size, str(chunks) @@ -62,9 +62,9 @@ class TestChunksList: _, document, _ = add_chunks if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: document.list_chunks(**params) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunks = document.list_chunks(**params) assert len(chunks) == expected_page_size, str(chunks) @@ -106,9 +106,9 @@ class TestChunksList: params = {"id": chunk_id} if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: document.list_chunks(**params) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunks = document.list_chunks(**params) if params["id"] in [None, ""]: diff --git a/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_retrieval_chunks.py b/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_retrieval_chunks.py index df9d3ce89..2834cfba9 100644 --- a/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_retrieval_chunks.py +++ b/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_retrieval_chunks.py @@ -38,9 +38,9 @@ class TestChunksRetrieval: payload["document_ids"] = [document.id] if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.retrieve(**payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunks = client.retrieve(**payload) assert len(chunks) == expected_page_size, str(chunks) @@ -83,9 +83,9 @@ class TestChunksRetrieval: payload.update({"question": "chunk", "dataset_ids": [dataset.id]}) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.retrieve(**payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunks = client.retrieve(**payload) assert len(chunks) == expected_page_size, str(chunks) @@ -116,9 +116,9 @@ class TestChunksRetrieval: payload.update({"question": "chunk", "dataset_ids": [dataset.id]}) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.retrieve(**payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunks = client.retrieve(**payload) assert len(chunks) == expected_page_size, str(chunks) @@ -143,9 +143,9 @@ class TestChunksRetrieval: payload.update({"question": "chunk", "dataset_ids": [dataset.id]}) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.retrieve(**payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunks = client.retrieve(**payload) assert len(chunks) == expected_page_size, str(chunks) @@ -192,9 +192,9 @@ class TestChunksRetrieval: payload.update({"question": "chunk", "dataset_ids": [dataset.id]}) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.retrieve(**payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunks = client.retrieve(**payload) assert len(chunks) == expected_page_size, str(chunks) @@ -212,9 +212,9 @@ class TestChunksRetrieval: payload.update({"question": "chunk", "dataset_ids": [dataset.id]}) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.retrieve(**payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunks = client.retrieve(**payload) assert len(chunks) > 0, str(chunks) @@ -235,9 +235,9 @@ class TestChunksRetrieval: payload.update({"question": "chunk test", "dataset_ids": [dataset.id]}) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.retrieve(**payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunks = client.retrieve(**payload) assert len(chunks) == expected_page_size, str(chunks) diff --git a/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_update_chunk.py b/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_update_chunk.py index 657c4a33d..93cc3eff7 100644 --- a/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_update_chunk.py +++ b/test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_update_chunk.py @@ -50,9 +50,9 @@ class TestUpdatedChunk: chunk = chunks[0] if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chunk.update(payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunk.update(payload) @@ -73,9 +73,9 @@ class TestUpdatedChunk: chunk = chunks[0] if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chunk.update(payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunk.update(payload) @@ -96,9 +96,9 @@ class TestUpdatedChunk: chunk = chunks[0] if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chunk.update(payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunk.update(payload) @@ -119,9 +119,9 @@ class TestUpdatedChunk: chunk = chunks[0] if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chunk.update(payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: chunk.update(payload) @@ -149,6 +149,6 @@ class TestUpdatedChunk: dataset, document, chunks = add_chunks dataset.delete_documents(ids=[document.id]) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chunks[0].update({}) - assert str(excinfo.value) in [f"You don't own the document {chunks[0].document_id}", f"Can't find this chunk {chunks[0].id}"], str(excinfo.value) + assert str(exception_info.value) in [f"You don't own the document {chunks[0].document_id}", f"Can't find this chunk {chunks[0].id}"], str(exception_info.value) diff --git a/test/testcases/test_sdk_api/test_dataset_mangement/test_create_dataset.py b/test/testcases/test_sdk_api/test_dataset_mangement/test_create_dataset.py index a97cb66c8..0eee167c7 100644 --- a/test/testcases/test_sdk_api/test_dataset_mangement/test_create_dataset.py +++ b/test/testcases/test_sdk_api/test_dataset_mangement/test_create_dataset.py @@ -38,9 +38,9 @@ class TestAuthorization: ) def test_auth_invalid(self, invalid_auth, expected_message): client = RAGFlow(invalid_auth, HOST_ADDRESS) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_dataset(**{"name": "auth_test"}) - assert str(excinfo.value) == expected_message + assert str(exception_info.value) == expected_message @pytest.mark.usefixtures("clear_datasets") @@ -85,9 +85,9 @@ class TestDatasetCreate: ids=["empty_name", "space_name", "too_long_name", "invalid_name", "None_name"], ) def test_name_invalid(self, client, name, expected_message): - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_dataset(**{"name": name}) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) @pytest.mark.p3 def test_name_duplicated(self, client): @@ -120,9 +120,9 @@ class TestDatasetCreate: @pytest.mark.p2 def test_avatar_exceeds_limit_length(self, client): payload = {"name": "avatar_exceeds_limit_length", "avatar": "a" * 65536} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_dataset(**payload) - assert "String should have at most 65535 characters" in str(excinfo.value), str(excinfo.value) + assert "String should have at most 65535 characters" in str(exception_info.value), str(exception_info.value) @pytest.mark.p3 @pytest.mark.parametrize( @@ -141,9 +141,9 @@ class TestDatasetCreate: "name": name, "avatar": f"{prefix}{encode_avatar(fn)}", } - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_dataset(**payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) @pytest.mark.p3 def test_avatar_unset(self, client): @@ -160,9 +160,9 @@ class TestDatasetCreate: @pytest.mark.p2 def test_description_exceeds_limit_length(self, client): payload = {"name": "description_exceeds_limit_length", "description": "a" * 65536} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_dataset(**payload) - assert "String should have at most 65535 characters" in str(excinfo.value), str(excinfo.value) + assert "String should have at most 65535 characters" in str(exception_info.value), str(exception_info.value) @pytest.mark.p3 def test_description_unset(self, client): @@ -203,12 +203,12 @@ class TestDatasetCreate: ) def test_embedding_model_invalid(self, client, name, embedding_model): payload = {"name": name, "embedding_model": embedding_model} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_dataset(**payload) if "tenant_no_auth" in name: - assert str(excinfo.value) == f"Unauthorized model: <{embedding_model}>", str(excinfo.value) + assert str(exception_info.value) == f"Unauthorized model: <{embedding_model}>", str(exception_info.value) else: - assert str(excinfo.value) == f"Unsupported model: <{embedding_model}>", str(excinfo.value) + assert str(exception_info.value) == f"Unsupported model: <{embedding_model}>", str(exception_info.value) @pytest.mark.p2 @pytest.mark.parametrize( @@ -226,12 +226,12 @@ class TestDatasetCreate: ) def test_embedding_model_format(self, client, name, embedding_model): payload = {"name": name, "embedding_model": embedding_model} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_dataset(**payload) if name in ["empty", "space", "missing_at"]: - assert "Embedding model identifier must follow @ format" in str(excinfo.value), str(excinfo.value) + assert "Embedding model identifier must follow @ format" in str(exception_info.value), str(exception_info.value) else: - assert "Both model_name and provider must be non-empty strings" in str(excinfo.value), str(excinfo.value) + assert "Both model_name and provider must be non-empty strings" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 def test_embedding_model_unset(self, client): @@ -273,9 +273,9 @@ class TestDatasetCreate: ) def test_permission_invalid(self, client, name, permission): payload = {"name": name, "permission": permission} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_dataset(**payload) - assert "Input should be 'me' or 'team'" in str(excinfo.value) + assert "Input should be 'me' or 'team'" in str(exception_info.value) @pytest.mark.p2 def test_permission_unset(self, client): @@ -286,9 +286,9 @@ class TestDatasetCreate: @pytest.mark.p3 def test_permission_none(self, client): payload = {"name": "permission_none", "permission": None} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_dataset(**payload) - assert "not instance of" in str(excinfo.value), str(excinfo.value) + assert "not instance of" in str(exception_info.value), str(exception_info.value) @pytest.mark.p1 @pytest.mark.parametrize( @@ -325,9 +325,9 @@ class TestDatasetCreate: ) def test_chunk_method_invalid(self, client, name, chunk_method): payload = {"name": name, "chunk_method": chunk_method} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_dataset(**payload) - assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in str(excinfo.value), str(excinfo.value) + assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 def test_chunk_method_unset(self, client): @@ -338,9 +338,9 @@ class TestDatasetCreate: @pytest.mark.p3 def test_chunk_method_none(self, client): payload = {"name": "chunk_method_none", "chunk_method": None} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_dataset(**payload) - assert "not instance of" in str(excinfo.value), str(excinfo.value) + assert "not instance of" in str(exception_info.value), str(exception_info.value) @pytest.mark.p1 @pytest.mark.parametrize( @@ -576,9 +576,9 @@ class TestDatasetCreate: def test_parser_config_invalid(self, client, name, parser_config, expected_message): parser_config_o = DataSet.ParserConfig(client, parser_config) payload = {"name": name, "parser_config": parser_config_o} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_dataset(**payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 def test_parser_config_empty(self, client): @@ -631,9 +631,9 @@ class TestDatasetCreate: ], ) def test_unsupported_field(self, client, payload): - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.create_dataset(**payload) - assert "got an unexpected keyword argument" in str(excinfo.value), str(excinfo.value) + assert "got an unexpected keyword argument" in str(exception_info.value), str(exception_info.value) @pytest.mark.usefixtures("clear_datasets") diff --git a/test/testcases/test_sdk_api/test_dataset_mangement/test_delete_datasets.py b/test/testcases/test_sdk_api/test_dataset_mangement/test_delete_datasets.py index 5a27d89bc..9939a30d5 100644 --- a/test/testcases/test_sdk_api/test_dataset_mangement/test_delete_datasets.py +++ b/test/testcases/test_sdk_api/test_dataset_mangement/test_delete_datasets.py @@ -33,9 +33,9 @@ class TestAuthorization: ) def test_auth_invalid(self, invalid_auth, expected_message): client = RAGFlow(invalid_auth, HOST_ADDRESS) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.delete_datasets() - assert str(excinfo.value) == expected_message + assert str(exception_info.value) == expected_message class TestCapability: @@ -71,6 +71,7 @@ class TestDatasetsDelete: ids=["single_dataset", "multiple_datasets"], ) def test_ids(self, client, add_datasets_func, func, remaining): + payload = None if callable(func): payload = func([dataset.id for dataset in add_datasets_func]) client.delete_datasets(**payload) @@ -100,9 +101,9 @@ class TestDatasetsDelete: @pytest.mark.usefixtures("add_dataset_func") def test_id_not_uuid(self, client): payload = {"ids": ["not_uuid"]} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.delete_datasets(**payload) - assert "Invalid UUID1 format" in str(excinfo.value), str(excinfo.value) + assert "Invalid UUID1 format" in str(exception_info.value), str(exception_info.value) datasets = client.list_datasets() assert len(datasets) == 1, str(datasets) @@ -111,17 +112,17 @@ class TestDatasetsDelete: @pytest.mark.usefixtures("add_dataset_func") def test_id_not_uuid1(self, client): payload = {"ids": [uuid.uuid4().hex]} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.delete_datasets(**payload) - assert "Invalid UUID1 format" in str(excinfo.value), str(excinfo.value) + assert "Invalid UUID1 format" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 @pytest.mark.usefixtures("add_dataset_func") def test_id_wrong_uuid(self, client): payload = {"ids": ["d94a8dc02c9711f0930f7fbc369eab6d"]} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.delete_datasets(**payload) - assert "lacks permission for dataset" in str(excinfo.value), str(excinfo.value) + assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value) datasets = client.list_datasets() assert len(datasets) == 1, str(datasets) @@ -138,9 +139,9 @@ class TestDatasetsDelete: def test_ids_partial_invalid(self, client, add_datasets_func, func): if callable(func): payload = func([dataset.id for dataset in add_datasets_func]) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.delete_datasets(**payload) - assert "lacks permission for dataset" in str(excinfo.value), str(excinfo.value) + assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value) datasets = client.list_datasets() assert len(datasets) == 3, str(datasets) @@ -149,9 +150,9 @@ class TestDatasetsDelete: def test_ids_duplicate(self, client, add_datasets_func): dataset_ids = [dataset.id for dataset in add_datasets_func] payload = {"ids": dataset_ids + dataset_ids} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.delete_datasets(**payload) - assert "Duplicate ids:" in str(excinfo.value), str(excinfo.value) + assert "Duplicate ids:" in str(exception_info.value), str(exception_info.value) datasets = client.list_datasets() assert len(datasets) == 3, str(datasets) @@ -162,17 +163,17 @@ class TestDatasetsDelete: payload = {"ids": dataset_ids} client.delete_datasets(**payload) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.delete_datasets(**payload) - assert "lacks permission for dataset" in str(excinfo.value), str(excinfo.value) + assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 @pytest.mark.usefixtures("add_dataset_func") def test_field_unsupported(self, client): payload = {"unknown_field": "unknown_field"} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.delete_datasets(**payload) - assert "got an unexpected keyword argument 'unknown_field'" in str(excinfo.value), str(excinfo.value) + assert "got an unexpected keyword argument 'unknown_field'" in str(exception_info.value), str(exception_info.value) datasets = client.list_datasets() assert len(datasets) == 1, str(datasets) diff --git a/test/testcases/test_sdk_api/test_dataset_mangement/test_list_datasets.py b/test/testcases/test_sdk_api/test_dataset_mangement/test_list_datasets.py index 0a3e237d0..0a84a363f 100644 --- a/test/testcases/test_sdk_api/test_dataset_mangement/test_list_datasets.py +++ b/test/testcases/test_sdk_api/test_dataset_mangement/test_list_datasets.py @@ -32,9 +32,9 @@ class TestAuthorization: ) def test_auth_invalid(self, invalid_auth, expected_message): client = RAGFlow(invalid_auth, HOST_ADDRESS) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets() - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) class TestCapability: @@ -46,7 +46,7 @@ class TestCapability: executor.submit( client.list_datasets, ) - for i in range(count) + for _ in range(count) ] responses = list(as_completed(futures)) assert len(responses) == count, responses @@ -89,16 +89,16 @@ class TestDatasetsList: ids=["page_0", "page_a"], ) def test_page_invalid(self, client, params, expected_message): - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets(**params) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 def test_page_none(self, client): params = {"page": None} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets(**params) - assert "not instance of" in str(excinfo.value), str(excinfo.value) + assert "not instance of" in str(exception_info.value), str(exception_info.value) @pytest.mark.p1 @pytest.mark.parametrize( @@ -124,16 +124,16 @@ class TestDatasetsList: ], ) def test_page_size_invalid(self, client, params, expected_message): - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets(**params) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 def test_page_size_none(self, client): params = {"page_size": None} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets(**params) - assert "not instance of" in str(excinfo.value), str(excinfo.value) + assert "not instance of" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 @pytest.mark.parametrize( @@ -160,16 +160,16 @@ class TestDatasetsList: ids=["empty", "unknown", "orderby_create_time_upper", "orderby_update_time_upper", "whitespace"], ) def test_orderby_invalid(self, client, params): - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets(**params) - assert "Input should be 'create_time' or 'update_time'" in str(excinfo.value), str(excinfo.value) + assert "Input should be 'create_time' or 'update_time'" in str(exception_info.value), str(exception_info.value) @pytest.mark.p3 def test_orderby_none(self, client): params = {"orderby": None} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets(**params) - assert "not instance of" in str(excinfo.value), str(excinfo.value) + assert "not instance of" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 @pytest.mark.parametrize( @@ -193,16 +193,16 @@ class TestDatasetsList: ids=["float_value", "invalid_string"], ) def test_desc_invalid(self, client, params): - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets(**params) - assert "not instance of" in str(excinfo.value), str(excinfo.value) + assert "not instance of" in str(exception_info.value), str(exception_info.value) @pytest.mark.p3 def test_desc_none(self, client): params = {"desc": None} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets(**params) - assert "not instance of" in str(excinfo.value), str(excinfo.value) + assert "not instance of" in str(exception_info.value), str(exception_info.value) @pytest.mark.p1 def test_name(self, client): @@ -214,9 +214,9 @@ class TestDatasetsList: @pytest.mark.p2 def test_name_wrong(self, client): params = {"name": "wrong name"} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets(**params) - assert "lacks permission for dataset" in str(excinfo.value), str(excinfo.value) + assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 def test_name_empty(self, client): @@ -241,30 +241,30 @@ class TestDatasetsList: @pytest.mark.p2 def test_id_not_uuid(self, client): params = {"id": "not_uuid"} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets(**params) - assert "Invalid UUID1 format" in str(excinfo.value), str(excinfo.value) + assert "Invalid UUID1 format" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 def test_id_not_uuid1(self, client): params = {"id": uuid.uuid4().hex} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets(**params) - assert "Invalid UUID1 format" in str(excinfo.value), str(excinfo.value) + assert "Invalid UUID1 format" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 def test_id_wrong_uuid(self, client): params = {"id": "d94a8dc02c9711f0930f7fbc369eab6d"} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets(**params) - assert "lacks permission for dataset" in str(excinfo.value), str(excinfo.value) + assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 def test_id_empty(self, client): params = {"id": ""} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets(**params) - assert "Invalid UUID1 format" in str(excinfo.value), str(excinfo.value) + assert "Invalid UUID1 format" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 def test_id_none(self, client): @@ -282,6 +282,7 @@ class TestDatasetsList: ids=["name_and_id_match", "name_and_id_mismatch"], ) def test_name_and_id(self, client, add_datasets, func, name, expected_num): + params = None if callable(func): params = {"id": func(add_datasets), "name": name} datasets = client.list_datasets(**params) @@ -301,13 +302,13 @@ class TestDatasetsList: params = {"id": dataset_id(add_datasets), "name": name} else: params = {"id": dataset_id, "name": name} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets(**params) - assert "lacks permission for dataset" in str(excinfo.value), str(excinfo.value) + assert "lacks permission for dataset" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 def test_field_unsupported(self, client): params = {"unknown_field": "unknown_field"} - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: client.list_datasets(**params) - assert "got an unexpected keyword argument" in str(excinfo.value), str(excinfo.value) + assert "got an unexpected keyword argument" in str(exception_info.value), str(exception_info.value) diff --git a/test/testcases/test_sdk_api/test_dataset_mangement/test_update_dataset.py b/test/testcases/test_sdk_api/test_dataset_mangement/test_update_dataset.py index df5d9fb73..e0c27c9f1 100644 --- a/test/testcases/test_sdk_api/test_dataset_mangement/test_update_dataset.py +++ b/test/testcases/test_sdk_api/test_dataset_mangement/test_update_dataset.py @@ -30,9 +30,9 @@ class TestRquest: @pytest.mark.p2 def test_payload_empty(self, add_dataset_func): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({}) - assert "No properties were modified" in str(excinfo.value), str(excinfo.value) + assert "No properties were modified" in str(exception_info.value), str(exception_info.value) class TestCapability: @@ -74,25 +74,25 @@ class TestDatasetUpdate: ) def test_name_invalid(self, add_dataset_func, name, expected_message): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({"name": name}) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) @pytest.mark.p3 def test_name_duplicated(self, add_datasets_func): datasets = add_datasets_func name = "dataset_1" - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: datasets[0].update({"name": name}) - assert f"Dataset name '{name}' already exists" in str(excinfo.value), str(excinfo.value) + assert f"Dataset name '{name}' already exists" in str(exception_info.value), str(exception_info.value) @pytest.mark.p3 def test_name_case_insensitive(self, add_datasets_func): dataset = add_datasets_func[0] name = "DATASET_1" - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({"name": name}) - assert f"Dataset name '{name}' already exists" in str(excinfo.value), str(excinfo.value) + assert f"Dataset name '{name}' already exists" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 def test_avatar(self, client, add_dataset_func, tmp_path): @@ -108,9 +108,9 @@ class TestDatasetUpdate: @pytest.mark.p2 def test_avatar_exceeds_limit_length(self, add_dataset_func): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({"avatar": "a" * 65536}) - assert "String should have at most 65535 characters" in str(excinfo.value), str(excinfo.value) + assert "String should have at most 65535 characters" in str(exception_info.value), str(exception_info.value) @pytest.mark.p3 @pytest.mark.parametrize( @@ -126,9 +126,9 @@ class TestDatasetUpdate: def test_avatar_invalid_prefix(self, add_dataset_func, tmp_path, avatar_prefix, expected_message): dataset = add_dataset_func fn = create_image_file(tmp_path / "ragflow_test.png") - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({"avatar": f"{avatar_prefix}{encode_avatar(fn)}"}) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) @pytest.mark.p3 def test_avatar_none(self, client, add_dataset_func): @@ -151,9 +151,9 @@ class TestDatasetUpdate: @pytest.mark.p2 def test_description_exceeds_limit_length(self, add_dataset_func): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({"description": "a" * 65536}) - assert "String should have at most 65535 characters" in str(excinfo.value), str(excinfo.value) + assert "String should have at most 65535 characters" in str(exception_info.value), str(exception_info.value) @pytest.mark.p3 def test_description_none(self, client, add_dataset_func): @@ -194,9 +194,9 @@ class TestDatasetUpdate: ) def test_embedding_model_invalid(self, add_dataset_func, name, embedding_model): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({"name": name, "embedding_model": embedding_model}) - error_msg = str(excinfo.value) + error_msg = str(exception_info.value) if "tenant_no_auth" in name: assert error_msg == f"Unauthorized model: <{embedding_model}>", error_msg else: @@ -218,9 +218,9 @@ class TestDatasetUpdate: ) def test_embedding_model_format(self, add_dataset_func, name, embedding_model): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({"name": name, "embedding_model": embedding_model}) - error_msg = str(excinfo.value) + error_msg = str(exception_info.value) if name in ["empty", "space", "missing_at"]: assert "Embedding model identifier must follow @ format" in error_msg, error_msg else: @@ -267,16 +267,16 @@ class TestDatasetUpdate: ) def test_permission_invalid(self, add_dataset_func, permission): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({"permission": permission}) - assert "Input should be 'me' or 'team'" in str(excinfo.value), str(excinfo.value) + assert "Input should be 'me' or 'team'" in str(exception_info.value), str(exception_info.value) @pytest.mark.p3 def test_permission_none(self, add_dataset_func): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({"permission": None}) - assert "Input should be 'me' or 'team'" in str(excinfo.value), str(excinfo.value) + assert "Input should be 'me' or 'team'" in str(exception_info.value), str(exception_info.value) @pytest.mark.p1 @pytest.mark.parametrize( @@ -317,16 +317,16 @@ class TestDatasetUpdate: ) def test_chunk_method_invalid(self, add_dataset_func, chunk_method): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({"chunk_method": chunk_method}) - assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in str(excinfo.value), str(excinfo.value) + assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in str(exception_info.value), str(exception_info.value) @pytest.mark.p3 def test_chunk_method_none(self, add_dataset_func): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({"chunk_method": None}) - assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in str(excinfo.value), str(excinfo.value) + assert "Input should be 'naive', 'book', 'email', 'laws', 'manual', 'one', 'paper', 'picture', 'presentation', 'qa', 'table' or 'tag'" in str(exception_info.value), str(exception_info.value) @pytest.mark.skipif(os.getenv("DOC_ENGINE") == "infinity", reason="#8208") @pytest.mark.p2 @@ -359,9 +359,9 @@ class TestDatasetUpdate: @pytest.mark.p2 def test_pagerank_infinity(self, client, add_dataset_func): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({"pagerank": 50}) - assert "'pagerank' can only be set when doc_engine is elasticsearch" in str(excinfo.value), str(excinfo.value) + assert "'pagerank' can only be set when doc_engine is elasticsearch" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 @pytest.mark.parametrize( @@ -374,16 +374,16 @@ class TestDatasetUpdate: ) def test_pagerank_invalid(self, add_dataset_func, pagerank, expected_message): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({"pagerank": pagerank}) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) @pytest.mark.p3 def test_pagerank_none(self, add_dataset_func): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({"pagerank": None}) - assert "Input should be a valid integer" in str(excinfo.value), str(excinfo.value) + assert "Input should be a valid integer" in str(exception_info.value), str(exception_info.value) @pytest.mark.p1 @pytest.mark.parametrize( @@ -625,9 +625,9 @@ class TestDatasetUpdate: ) def test_parser_config_invalid(self, add_dataset_func, parser_config, expected_message): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update({"parser_config": parser_config}) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 def test_parser_config_empty(self, client, add_dataset_func): @@ -723,9 +723,9 @@ class TestDatasetUpdate: ) def test_field_unsupported(self, add_dataset_func, payload): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.update(payload) - assert "Extra inputs are not permitted" in str(excinfo.value), str(excinfo.value) + assert "Extra inputs are not permitted" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 def test_field_unset(self, client, add_dataset_func): diff --git a/test/testcases/test_sdk_api/test_file_management_within_dataset/test_delete_documents.py b/test/testcases/test_sdk_api/test_file_management_within_dataset/test_delete_documents.py index c90d4294e..35f146a4d 100644 --- a/test/testcases/test_sdk_api/test_file_management_within_dataset/test_delete_documents.py +++ b/test/testcases/test_sdk_api/test_file_management_within_dataset/test_delete_documents.py @@ -45,9 +45,9 @@ class TestDocumentsDeletion: payload = payload([document.id for document in documents]) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.delete_documents(**payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: dataset.delete_documents(**payload) @@ -67,9 +67,9 @@ class TestDocumentsDeletion: dataset, documents = add_documents_func payload = payload([document.id for document in documents]) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.delete_documents(**payload) - assert "Documents not found: ['invalid_id']" in str(excinfo.value), str(excinfo.value) + assert "Documents not found: ['invalid_id']" in str(exception_info.value), str(exception_info.value) documents = dataset.list_documents() assert len(documents) == 0, str(documents) @@ -79,9 +79,9 @@ class TestDocumentsDeletion: dataset, documents = add_documents_func document_ids = [document.id for document in documents] dataset.delete_documents(ids=document_ids) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.delete_documents(ids=document_ids) - assert "Documents not found" in str(excinfo.value), str(excinfo.value) + assert "Documents not found" in str(exception_info.value), str(exception_info.value) @pytest.mark.p2 def test_duplicate_deletion(self, add_documents_func): diff --git a/test/testcases/test_sdk_api/test_file_management_within_dataset/test_list_documents.py b/test/testcases/test_sdk_api/test_file_management_within_dataset/test_list_documents.py index 189093da2..9e8cea30d 100644 --- a/test/testcases/test_sdk_api/test_file_management_within_dataset/test_list_documents.py +++ b/test/testcases/test_sdk_api/test_file_management_within_dataset/test_list_documents.py @@ -51,9 +51,9 @@ class TestDocumentsList: def test_page(self, add_documents, params, expected_page_size, expected_message): dataset, _ = add_documents if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.list_documents(**params) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: documents = dataset.list_documents(**params) assert len(documents) == expected_page_size, str(documents) @@ -84,9 +84,9 @@ class TestDocumentsList: def test_page_size(self, add_documents, params, expected_page_size, expected_message): dataset, _ = add_documents if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.list_documents(**params) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: documents = dataset.list_documents(**params) assert len(documents) == expected_page_size, str(documents) @@ -105,9 +105,9 @@ class TestDocumentsList: def test_orderby(self, add_documents, params, expected_message): dataset, _ = add_documents if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.list_documents(**params) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: dataset.list_documents(**params) @@ -129,9 +129,9 @@ class TestDocumentsList: def test_desc(self, add_documents, params, expected_message): dataset, _ = add_documents if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.list_documents(**params) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: dataset.list_documents(**params) @@ -164,9 +164,9 @@ class TestDocumentsList: def test_name(self, add_documents, params, expected_num, expected_message): dataset, _ = add_documents if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.list_documents(**params) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: documents = dataset.list_documents(**params) assert len(documents) == expected_num, str(documents) @@ -191,9 +191,9 @@ class TestDocumentsList: params = {"id": document_id} if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.list_documents(**params) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: documents = dataset.list_documents(**params) assert len(documents) == expected_num, str(documents) @@ -215,9 +215,9 @@ class TestDocumentsList: params = {"id": document_id(documents) if callable(document_id) else document_id, "name": name} if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.list_documents(**params) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: documents = dataset.list_documents(**params) assert len(documents) == expected_num, str(documents) @@ -242,6 +242,6 @@ class TestDocumentsList: def test_invalid_params(self, add_documents): dataset, _ = add_documents params = {"a": "b"} - with pytest.raises(TypeError) as excinfo: + with pytest.raises(TypeError) as exception_info: dataset.list_documents(**params) - assert "got an unexpected keyword argument" in str(excinfo.value), str(excinfo.value) + assert "got an unexpected keyword argument" in str(exception_info.value), str(exception_info.value) diff --git a/test/testcases/test_sdk_api/test_file_management_within_dataset/test_parse_documents.py b/test/testcases/test_sdk_api/test_file_management_within_dataset/test_parse_documents.py index 2b94d488e..3ff21178d 100644 --- a/test/testcases/test_sdk_api/test_file_management_within_dataset/test_parse_documents.py +++ b/test/testcases/test_sdk_api/test_file_management_within_dataset/test_parse_documents.py @@ -69,9 +69,9 @@ class TestDocumentsParse: payload = payload([doc.id for doc in documents]) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.async_parse_documents(**payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: dataset.async_parse_documents(**payload) condition(dataset, payload["document_ids"]) @@ -90,9 +90,9 @@ class TestDocumentsParse: document_ids = [doc.id for doc in documents] payload = payload(document_ids) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.async_parse_documents(**payload) - assert "Documents not found: ['invalid_id']" in str(excinfo.value), str(excinfo.value) + assert "Documents not found: ['invalid_id']" in str(exception_info.value), str(exception_info.value) condition(dataset, document_ids) validate_document_details(dataset, document_ids) @@ -117,9 +117,9 @@ class TestDocumentsParse: @pytest.mark.p3 def test_parse_100_files(add_dataset_func, tmp_path): @wait_for(200, 1, "Document parsing timeout") - def condition(_dataset: DataSet, _count: int): - documents = _dataset.list_documents(page_size=_count * 2) - for document in documents: + def condition_inner(_dataset: DataSet, _count: int): + docs = _dataset.list_documents(page_size=_count * 2) + for document in docs: if document.run != "DONE": return False return True @@ -130,16 +130,16 @@ def test_parse_100_files(add_dataset_func, tmp_path): document_ids = [doc.id for doc in documents] dataset.async_parse_documents(document_ids=document_ids) - condition(dataset, count) + condition_inner(dataset, count) validate_document_details(dataset, document_ids) @pytest.mark.p3 def test_concurrent_parse(add_dataset_func, tmp_path): @wait_for(200, 1, "Document parsing timeout") - def condition(_dataset: DataSet, _count: int): - documents = _dataset.list_documents(page_size=_count * 2) - for document in documents: + def condition_inner(_dataset: DataSet, _count: int): + docs = _dataset.list_documents(page_size=_count * 2) + for document in docs: if document.run != "DONE": return False return True @@ -158,5 +158,5 @@ def test_concurrent_parse(add_dataset_func, tmp_path): responses = list(as_completed(futures)) assert len(responses) == count, responses - condition(dataset, count) + condition_inner(dataset, count) validate_document_details(dataset, document_ids) diff --git a/test/testcases/test_sdk_api/test_file_management_within_dataset/test_update_document.py b/test/testcases/test_sdk_api/test_file_management_within_dataset/test_update_document.py index b7b33281e..00466ef33 100644 --- a/test/testcases/test_sdk_api/test_file_management_within_dataset/test_update_document.py +++ b/test/testcases/test_sdk_api/test_file_management_within_dataset/test_update_document.py @@ -39,9 +39,9 @@ class TestDocumentsUpdated: document = documents[0] if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: document.update({"name": name}) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: document.update({"name": name}) updated_doc = dataset.list_documents(id=document.id)[0] @@ -60,9 +60,9 @@ class TestDocumentsUpdated: document = documents[0] if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: document.update({"meta_fields": meta_fields}) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: document.update({"meta_fields": meta_fields}) @@ -92,9 +92,9 @@ class TestDocumentsUpdated: document = documents[0] if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: document.update({"chunk_method": chunk_method}) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: document.update({"chunk_method": chunk_method}) updated_doc = dataset.list_documents(id=document.id)[0] @@ -193,9 +193,9 @@ class TestDocumentsUpdated: _, documents = add_documents document = documents[0] - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: document.update(payload) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) class TestUpdateDocumentParserConfig: @@ -382,9 +382,9 @@ class TestUpdateDocumentParserConfig: update_data = {"chunk_method": chunk_method, "parser_config": parser_config} if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: document.update(update_data) - assert expected_message in str(excinfo.value), str(excinfo.value) + assert expected_message in str(exception_info.value), str(exception_info.value) else: document.update(update_data) updated_doc = dataset.list_documents(id=document.id)[0] diff --git a/test/testcases/test_sdk_api/test_file_management_within_dataset/test_upload_documents.py b/test/testcases/test_sdk_api/test_file_management_within_dataset/test_upload_documents.py index 72034e27d..6493782e5 100644 --- a/test/testcases/test_sdk_api/test_file_management_within_dataset/test_upload_documents.py +++ b/test/testcases/test_sdk_api/test_file_management_within_dataset/test_upload_documents.py @@ -76,16 +76,16 @@ class TestDocumentsUpload: with fp.open("rb") as f: blob = f.read() - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.upload_documents([{"display_name": fp.name, "blob": blob}]) - assert str(excinfo.value) == f"ragflow_test.{file_type}: This type of file has not been supported yet!", str(excinfo.value) + assert str(exception_info.value) == f"ragflow_test.{file_type}: This type of file has not been supported yet!", str(exception_info.value) @pytest.mark.p2 def test_missing_file(self, add_dataset_func): dataset = add_dataset_func - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.upload_documents([]) - assert str(excinfo.value) == "No file part!", str(excinfo.value) + assert str(exception_info.value) == "No file part!", str(exception_info.value) @pytest.mark.p3 def test_empty_file(self, add_dataset_func, tmp_path): @@ -108,9 +108,9 @@ class TestDocumentsUpload: with fp.open("rb") as f: blob = f.read() - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: dataset.upload_documents([{"display_name": "", "blob": blob}]) - assert str(excinfo.value) == "No file selected!", str(excinfo.value) + assert str(exception_info.value) == "No file selected!", str(exception_info.value) @pytest.mark.p2 def test_filename_max_length(self, add_dataset_func, tmp_path): diff --git a/test/testcases/test_sdk_api/test_session_management/conftest.py b/test/testcases/test_sdk_api/test_session_management/conftest.py index 08dfd08d2..eaab3a487 100644 --- a/test/testcases/test_sdk_api/test_session_management/conftest.py +++ b/test/testcases/test_sdk_api/test_session_management/conftest.py @@ -25,7 +25,8 @@ def add_sessions_with_chat_assistant(request: FixtureRequest, add_chat_assistant for chat_assistant in chat_assistants: try: chat_assistant.delete_sessions(ids=None) - except Exception: + except Exception as e: + print(f"Exception: {e}") pass request.addfinalizer(cleanup) @@ -40,8 +41,8 @@ def add_sessions_with_chat_assistant_func(request: FixtureRequest, add_chat_assi for chat_assistant in chat_assistants: try: chat_assistant.delete_sessions(ids=None) - except Exception: - pass + except Exception as e: + print(f"Exception: {e}") request.addfinalizer(cleanup) diff --git a/test/testcases/test_sdk_api/test_session_management/test_create_session_with_chat_assistant.py b/test/testcases/test_sdk_api/test_session_management/test_create_session_with_chat_assistant.py index 084c7122c..e7bb41262 100644 --- a/test/testcases/test_sdk_api/test_session_management/test_create_session_with_chat_assistant.py +++ b/test/testcases/test_sdk_api/test_session_management/test_create_session_with_chat_assistant.py @@ -43,9 +43,9 @@ class TestSessionWithChatAssistantCreate: chat_assistant.create_session(name=name.upper()) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chat_assistant.create_session(name=name) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: session = chat_assistant.create_session(name=name) assert session.name == name, str(session) @@ -71,6 +71,6 @@ class TestSessionWithChatAssistantCreate: chat_assistant = chat_assistants[0] client.delete_chats(ids=[chat_assistant.id]) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chat_assistant.create_session(name="valid_name") - assert "You do not own the assistant" in str(excinfo.value) + assert "You do not own the assistant" in str(exception_info.value) diff --git a/test/testcases/test_sdk_api/test_session_management/test_delete_sessions_with_chat_assistant.py b/test/testcases/test_sdk_api/test_session_management/test_delete_sessions_with_chat_assistant.py index 0c3c0ebe4..5d118af6c 100644 --- a/test/testcases/test_sdk_api/test_session_management/test_delete_sessions_with_chat_assistant.py +++ b/test/testcases/test_sdk_api/test_session_management/test_delete_sessions_with_chat_assistant.py @@ -46,9 +46,9 @@ class TestSessionWithChatAssistantDelete: chat_assistant.delete_sessions(**session_ids) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chat_assistant.delete_sessions(**session_ids) - assert "The chat doesn't own the session" in str(excinfo.value) + assert "The chat doesn't own the session" in str(exception_info.value) @pytest.mark.p3 def test_duplicate_deletion(self, add_sessions_with_chat_assistant_func): @@ -98,9 +98,9 @@ class TestSessionWithChatAssistantDelete: payload = payload([session.id for session in sessions]) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chat_assistant.delete_sessions(**payload) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: chat_assistant.delete_sessions(**payload) diff --git a/test/testcases/test_sdk_api/test_session_management/test_list_sessions_with_chat_assistant.py b/test/testcases/test_sdk_api/test_session_management/test_list_sessions_with_chat_assistant.py index c2918848c..6889fd6ec 100644 --- a/test/testcases/test_sdk_api/test_session_management/test_list_sessions_with_chat_assistant.py +++ b/test/testcases/test_sdk_api/test_session_management/test_list_sessions_with_chat_assistant.py @@ -34,9 +34,9 @@ class TestSessionsWithChatAssistantList: def test_page(self, add_sessions_with_chat_assistant, params, expected_page_size, expected_message): chat_assistant, _ = add_sessions_with_chat_assistant if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chat_assistant.list_sessions(**params) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: sessions = chat_assistant.list_sessions(**params) assert len(sessions) == expected_page_size @@ -57,9 +57,9 @@ class TestSessionsWithChatAssistantList: def test_page_size(self, add_sessions_with_chat_assistant, params, expected_page_size, expected_message): chat_assistant, _ = add_sessions_with_chat_assistant if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chat_assistant.list_sessions(**params) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: sessions = chat_assistant.list_sessions(**params) assert len(sessions) == expected_page_size @@ -78,9 +78,9 @@ class TestSessionsWithChatAssistantList: def test_orderby(self, add_sessions_with_chat_assistant, params, expected_message): chat_assistant, _ = add_sessions_with_chat_assistant if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chat_assistant.list_sessions(**params) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: chat_assistant.list_sessions(**params) @@ -102,9 +102,9 @@ class TestSessionsWithChatAssistantList: def test_desc(self, add_sessions_with_chat_assistant, params, expected_message): chat_assistant, _ = add_sessions_with_chat_assistant if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chat_assistant.list_sessions(**params) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: chat_assistant.list_sessions(**params) @@ -121,9 +121,9 @@ class TestSessionsWithChatAssistantList: def test_name(self, add_sessions_with_chat_assistant, params, expected_num, expected_message): chat_assistant, _ = add_sessions_with_chat_assistant if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chat_assistant.list_sessions(**params) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: sessions = chat_assistant.list_sessions(**params) if params["name"] == "session_with_chat_assistant_1": @@ -149,9 +149,9 @@ class TestSessionsWithChatAssistantList: params = {"id": session_id} if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chat_assistant.list_sessions(**params) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: list_sessions = chat_assistant.list_sessions(**params) if "id" in params and params["id"] == sessions[0].id: @@ -177,9 +177,9 @@ class TestSessionsWithChatAssistantList: params = {"id": session_id, "name": name} if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chat_assistant.list_sessions(**params) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: list_sessions = chat_assistant.list_sessions(**params) assert len(list_sessions) == expected_num @@ -189,7 +189,7 @@ class TestSessionsWithChatAssistantList: count = 100 chat_assistant, _ = add_sessions_with_chat_assistant with ThreadPoolExecutor(max_workers=5) as executor: - futures = [executor.submit(chat_assistant.list_sessions) for i in range(count)] + futures = [executor.submit(chat_assistant.list_sessions) for _ in range(count)] responses = list(as_completed(futures)) assert len(responses) == count, responses @@ -198,6 +198,6 @@ class TestSessionsWithChatAssistantList: chat_assistant, _ = add_sessions_with_chat_assistant client.delete_chats(ids=[chat_assistant.id]) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: chat_assistant.list_sessions() - assert "You don't own the assistant" in str(excinfo.value) + assert "You don't own the assistant" in str(exception_info.value) diff --git a/test/testcases/test_sdk_api/test_session_management/test_update_session_with_chat_assistant.py b/test/testcases/test_sdk_api/test_session_management/test_update_session_with_chat_assistant.py index d0fa3e187..7c1bd5a9c 100644 --- a/test/testcases/test_sdk_api/test_session_management/test_update_session_with_chat_assistant.py +++ b/test/testcases/test_sdk_api/test_session_management/test_update_session_with_chat_assistant.py @@ -42,9 +42,9 @@ class TestSessionWithChatAssistantUpdate: session.update({"name": payload["name"].upper()}) if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: session.update(payload) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: session.update(payload) updated_session = chat_assistant.list_sessions(id=session.id)[0] @@ -72,9 +72,9 @@ class TestSessionWithChatAssistantUpdate: session = sessions[0] if expected_message: - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: session.update(payload) - assert expected_message in str(excinfo.value) + assert expected_message in str(exception_info.value) else: session.update(payload) @@ -93,6 +93,6 @@ class TestSessionWithChatAssistantUpdate: chat_assistant, sessions = add_sessions_with_chat_assistant_func client.delete_chats(ids=[chat_assistant.id]) - with pytest.raises(Exception) as excinfo: + with pytest.raises(Exception) as exception_info: sessions[0].update({"name": "valid_name"}) - assert "You do not own the session" in str(excinfo.value) + assert "You do not own the session" in str(exception_info.value)