Skip to content

Commit

Permalink
Trying to make CI robust against pytest.PytestUnraisableExceptionWarn…
Browse files Browse the repository at this point in the history
…ing (#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
  • Loading branch information
hemidactylus authored Sep 7, 2024
1 parent ffc925d commit cc40f28
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 22 deletions.
1 change: 1 addition & 0 deletions libs/astradb/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,4 @@ markers = [
"compile: mark placeholder test used to compile integration tests without running them",
]
asyncio_mode = "auto"
filterwarnings = "ignore::pytest.PytestUnraisableExceptionWarning"
28 changes: 24 additions & 4 deletions libs/astradb/tests/integration_tests/test_caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
24 changes: 17 additions & 7 deletions libs/astradb/tests/integration_tests/test_document_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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."):
Expand All @@ -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
19 changes: 16 additions & 3 deletions libs/astradb/tests/integration_tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
18 changes: 12 additions & 6 deletions libs/astradb/tests/integration_tests/test_vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit cc40f28

Please sign in to comment.