From cc40f28c5323a4fe3f4c6143bdd35d032cea0436 Mon Sep 17 00:00:00 2001 From: Stefano Lottini Date: Sat, 7 Sep 2024 09:41:46 +0200 Subject: [PATCH] Trying to make CI robust against pytest.PytestUnraisableExceptionWarning (#70) * trying to make CI robust against pytest.PytestUnraisableExceptionWarning * rephrasing the rec_warnings filter to include only deprecation warnings * all rec_warnings are filtered with positive issubclass check --- libs/astradb/pyproject.toml | 1 + .../tests/integration_tests/test_caches.py | 28 ++++++++++++++++--- .../test_chat_message_histories.py | 9 ++++-- .../test_document_loaders.py | 24 +++++++++++----- .../tests/integration_tests/test_storage.py | 19 +++++++++++-- .../integration_tests/test_vectorstores.py | 18 ++++++++---- 6 files changed, 77 insertions(+), 22 deletions(-) diff --git a/libs/astradb/pyproject.toml b/libs/astradb/pyproject.toml index 5113f69..c38ff52 100644 --- a/libs/astradb/pyproject.toml +++ b/libs/astradb/pyproject.toml @@ -120,3 +120,4 @@ markers = [ "compile: mark placeholder test used to compile integration tests without running them", ] asyncio_mode = "auto" +filterwarnings = "ignore::pytest.PytestUnraisableExceptionWarning" diff --git a/libs/astradb/tests/integration_tests/test_caches.py b/libs/astradb/tests/integration_tests/test_caches.py index 71819d3..62ef6a3 100644 --- a/libs/astradb/tests/integration_tests/test_caches.py +++ b/libs/astradb/tests/integration_tests/test_caches.py @@ -260,7 +260,12 @@ def test_cache_coreclients_init_sync( collection_name=collection_name, astra_db_client=core_astra_db, ) - assert len(rec_warnings) == 1 + f_rec_warnings = [ + wrn + for wrn in rec_warnings + if issubclass(wrn.category, DeprecationWarning) + ] + assert len(f_rec_warnings) == 1 assert cache_init_core.lookup("pr", "llms") == test_gens finally: cache_init_ok.astra_env.database.drop_collection(collection_name) @@ -293,7 +298,12 @@ async def test_cache_coreclients_init_async( astra_db_client=core_astra_db, setup_mode=SetupMode.ASYNC, ) - assert len(rec_warnings) == 1 + f_rec_warnings = [ + wrn + for wrn in rec_warnings + if issubclass(wrn.category, DeprecationWarning) + ] + assert len(f_rec_warnings) == 1 assert await cache_init_core.alookup("pr", "llms") == test_gens finally: await cache_init_ok.astra_env.async_database.drop_collection( @@ -329,7 +339,12 @@ def test_semcache_coreclients_init_sync( astra_db_client=core_astra_db, embedding=fake_embe, ) - assert len(rec_warnings) == 1 + f_rec_warnings = [ + wrn + for wrn in rec_warnings + if issubclass(wrn.category, DeprecationWarning) + ] + assert len(f_rec_warnings) == 1 assert cache_init_core.lookup("pr", "llms") == test_gens finally: cache_init_ok.astra_env.database.drop_collection(collection_name) @@ -365,7 +380,12 @@ async def test_semcache_coreclients_init_async( setup_mode=SetupMode.ASYNC, embedding=fake_embe, ) - assert len(rec_warnings) == 1 + f_rec_warnings = [ + wrn + for wrn in rec_warnings + if issubclass(wrn.category, DeprecationWarning) + ] + assert len(f_rec_warnings) == 1 assert await cache_init_core.alookup("pr", "llms") == test_gens finally: await cache_init_ok.astra_env.async_database.drop_collection( diff --git a/libs/astradb/tests/integration_tests/test_chat_message_histories.py b/libs/astradb/tests/integration_tests/test_chat_message_histories.py index a373bc7..a758a76 100644 --- a/libs/astradb/tests/integration_tests/test_chat_message_histories.py +++ b/libs/astradb/tests/integration_tests/test_chat_message_histories.py @@ -226,7 +226,12 @@ def test_chatms_coreclients_init_sync( session_id="gattini", astra_db_client=core_astra_db, ) - assert len(rec_warnings) == 1 + f_rec_warnings = [ + wrn + for wrn in rec_warnings + if issubclass(wrn.category, DeprecationWarning) + ] + assert len(f_rec_warnings) == 1 assert chatmh_init_core.messages == test_messages finally: chatmh_init_ok.astra_env.collection.drop() @@ -265,7 +270,7 @@ async def test_chatms_coreclients_init_async( f_rec_warnings = [ wrn for wrn in rec_warnings - if not issubclass(wrn.category, ResourceWarning) + if issubclass(wrn.category, DeprecationWarning) ] assert len(f_rec_warnings) == 1 assert await chatmh_init_core.aget_messages() == test_messages diff --git a/libs/astradb/tests/integration_tests/test_document_loaders.py b/libs/astradb/tests/integration_tests/test_document_loaders.py index 251253d..efe62fb 100644 --- a/libs/astradb/tests/integration_tests/test_document_loaders.py +++ b/libs/astradb/tests/integration_tests/test_document_loaders.py @@ -78,7 +78,10 @@ def test_astradb_loader_prefetched_sync( limit=22, filter_criteria={"foo": "bar"}, ) - assert len(rec_warnings) == 1 + f_rec_warnings = [ + wrn for wrn in rec_warnings if issubclass(wrn.category, UserWarning) + ] + assert len(f_rec_warnings) == 1 docs = loader.load() assert len(docs) == 22 @@ -174,9 +177,7 @@ async def test_astradb_loader_prefetched_async( ) # cleaning out 'spurious' "unclosed socket/transport..." warnings f_rec_warnings = [ - wrn - for wrn in rec_warnings - if not issubclass(wrn.category, ResourceWarning) + wrn for wrn in rec_warnings if issubclass(wrn.category, UserWarning) ] assert len(f_rec_warnings) == 1 @@ -276,7 +277,10 @@ def test_astradb_loader_coreclients_init( astra_db_client=core_astra_db, limit=1, ) - assert len(rec_warnings) == 1 + f_rec_warnings = [ + wrn for wrn in rec_warnings if issubclass(wrn.category, DeprecationWarning) + ] + assert len(f_rec_warnings) == 1 assert loader_init_core.load() == docs def test_astradb_loader_findoptions_deprecation( @@ -304,7 +308,10 @@ def test_astradb_loader_findoptions_deprecation( environment=astra_db_credentials["environment"], find_options={"limit": 1}, ) - assert len(rec_warnings) == 1 + f_rec_warnings = [ + wrn for wrn in rec_warnings if issubclass(wrn.category, DeprecationWarning) + ] + assert len(f_rec_warnings) == 1 assert loader_lo.load() == docs0 with pytest.raises(ValueError, match="Duplicate 'limit' directive supplied."): @@ -328,5 +335,8 @@ def test_astradb_loader_findoptions_deprecation( find_options={"planets": 8, "spiders": 40000}, limit=1, ) - assert len(rec_warnings) == 1 + f_rec_warnings = [ + wrn for wrn in rec_warnings if issubclass(wrn.category, DeprecationWarning) + ] + assert len(f_rec_warnings) == 1 assert loader_uo.load() == docs0 diff --git a/libs/astradb/tests/integration_tests/test_storage.py b/libs/astradb/tests/integration_tests/test_storage.py index 3b4ebd4..f3f48b0 100644 --- a/libs/astradb/tests/integration_tests/test_storage.py +++ b/libs/astradb/tests/integration_tests/test_storage.py @@ -366,7 +366,10 @@ def test_indexing_detection( namespace=astra_db_credentials["namespace"], environment=astra_db_credentials["environment"], ) - assert len(rec_warnings) == 1 + f_rec_warnings = [ + wrn for wrn in rec_warnings if issubclass(wrn.category, UserWarning) + ] + assert len(f_rec_warnings) == 1 # on a custom collection must error with pytest.raises( ValueError, match="is detected as having the following indexing policy" @@ -408,7 +411,12 @@ def test_store_coreclients_init_sync( collection_name=collection_name, astra_db_client=core_astra_db, ) - assert len(rec_warnings) == 1 + f_rec_warnings = [ + wrn + for wrn in rec_warnings + if issubclass(wrn.category, DeprecationWarning) + ] + assert len(f_rec_warnings) == 1 assert store_init_core.mget(["key"]) == ["val123"] finally: store_init_ok.astra_env.database.drop_collection(collection_name) @@ -440,7 +448,12 @@ async def test_store_coreclients_init_async( astra_db_client=core_astra_db, setup_mode=SetupMode.ASYNC, ) - assert len(rec_warnings) == 1 + f_rec_warnings = [ + wrn + for wrn in rec_warnings + if issubclass(wrn.category, DeprecationWarning) + ] + assert len(f_rec_warnings) == 1 assert await store_init_core.amget(["key"]) == ["val123"] finally: await store_init_ok.astra_env.async_database.drop_collection( diff --git a/libs/astradb/tests/integration_tests/test_vectorstores.py b/libs/astradb/tests/integration_tests/test_vectorstores.py index a13a505..53a80ce 100644 --- a/libs/astradb/tests/integration_tests/test_vectorstores.py +++ b/libs/astradb/tests/integration_tests/test_vectorstores.py @@ -1492,7 +1492,10 @@ def test_astradb_vectorstore_indexing_sync( namespace=astra_db_credentials["namespace"], environment=astra_db_credentials["environment"], ) - assert len(rec_warnings) == 1 + f_rec_warnings = [ + wrn for wrn in rec_warnings if issubclass(wrn.category, UserWarning) + ] + assert len(f_rec_warnings) == 1 # cleanup database.drop_collection("lc_legacy_coll") @@ -1626,9 +1629,7 @@ async def test_astradb_vectorstore_indexing_async( await leg_store.aadd_texts(["Triggering warning."]) # cleaning out 'spurious' "unclosed socket/transport..." warnings f_rec_warnings = [ - wrn - for wrn in rec_warnings - if not issubclass(wrn.category, ResourceWarning) + wrn for wrn in rec_warnings if issubclass(wrn.category, UserWarning) ] assert len(f_rec_warnings) == 1 @@ -1671,7 +1672,7 @@ def test_astradb_vectorstore_coreclients_init_sync( f_rec_warnings = [ wrn for wrn in rec_warnings - if not issubclass(wrn.category, ResourceWarning) + if issubclass(wrn.category, DeprecationWarning) ] assert len(f_rec_warnings) == 1 assert len(results) == 1 @@ -1715,7 +1716,12 @@ async def test_astradb_vectorstore_coreclients_init_async( ) results = await v_store_init_core.asimilarity_search("another", k=1) - assert len(rec_warnings) == 1 + f_rec_warnings = [ + wrn + for wrn in rec_warnings + if issubclass(wrn.category, DeprecationWarning) + ] + assert len(f_rec_warnings) == 1 assert len(results) == 1 assert results[0].page_content == "One text" finally: