Skip to content

Commit 92ae61b

Browse files
author
Erick Friis
authored
multiple: rely on asyncio_mode auto in tests (#27200)
1 parent 0a3e089 commit 92ae61b

File tree

32 files changed

+78
-91
lines changed

32 files changed

+78
-91
lines changed

libs/community/tests/integration_tests/chat_models/test_litellm_router.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ def test_litellm_router_streaming_callback(
266266
fake_completion.check_inputs(expected_num_calls=1)
267267

268268

269-
@pytest.mark.asyncio
270269
@pytest.mark.scheduled
271270
async def test_async_litellm_router(
272271
fake_completion: FakeCompletion, litellm_router: Any
@@ -295,7 +294,6 @@ async def test_async_litellm_router(
295294
fake_completion.check_inputs(expected_num_calls=2)
296295

297296

298-
@pytest.mark.asyncio
299297
@pytest.mark.scheduled
300298
async def test_async_litellm_router_streaming(
301299
fake_completion: FakeCompletion, litellm_router: Any

libs/community/tests/integration_tests/chat_models/test_qianfan_endpoint.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from typing import Any, cast
44

5-
import pytest
65
from langchain_core.callbacks import CallbackManager
76
from langchain_core.messages import (
87
AIMessage,
@@ -201,15 +200,13 @@ def test_stream() -> None:
201200
assert len(list(res)) >= 1
202201

203202

204-
@pytest.mark.asyncio
205203
async def test_async_invoke() -> None:
206204
chat = QianfanChatEndpoint() # type: ignore[call-arg]
207205
res = await chat.ainvoke([HumanMessage(content="Hello")])
208206
assert isinstance(res, BaseMessage)
209207
assert res.content != ""
210208

211209

212-
@pytest.mark.asyncio
213210
async def test_async_generate() -> None:
214211
"""Tests chat agenerate works."""
215212
chat = QianfanChatEndpoint() # type: ignore[call-arg]
@@ -229,7 +226,6 @@ async def test_async_generate() -> None:
229226
assert isinstance(generation.text, str)
230227

231228

232-
@pytest.mark.asyncio
233229
async def test_async_stream() -> None:
234230
chat = QianfanChatEndpoint(streaming=True) # type: ignore[call-arg]
235231
async for token in chat.astream(

libs/community/tests/integration_tests/chat_models/test_yuan2.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def test_chat_yuan2_streaming() -> None:
100100
assert isinstance(response, BaseMessage)
101101

102102

103-
@pytest.mark.asyncio
104103
async def test_async_chat_yuan2() -> None:
105104
"""Test async generation."""
106105
chat = ChatYuan2( # type: ignore[call-arg]
@@ -124,7 +123,6 @@ async def test_async_chat_yuan2() -> None:
124123
assert generation.text == generation.message.content
125124

126125

127-
@pytest.mark.asyncio
128126
async def test_async_chat_yuan2_streaming() -> None:
129127
"""Test that streaming correctly invokes on_llm_new_token callback."""
130128
callback_handler = FakeCallbackHandler()

libs/community/tests/integration_tests/indexes/test_document_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def test_update(manager: MongoDocumentManager) -> None:
4343
assert sorted(all_keys) == sorted(read_keys + updated_keys)
4444

4545

46-
@pytest.mark.asyncio
4746
@pytest.mark.requires("motor")
4847
async def test_aupdate(amanager: MongoDocumentManager) -> None:
4948
"""Test updating records in the MongoDB."""

libs/community/tests/integration_tests/llms/test_vertexai.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ def test_model_garden_generate(
150150
assert len(output.generations) == 2
151151

152152

153-
@pytest.mark.asyncio
154153
@pytest.mark.parametrize(
155154
"endpoint_os_variable_name,result_arg",
156155
[("FALCON_ENDPOINT_ID", "generated_text"), ("LLAMA_ENDPOINT_ID", None)],

libs/community/tests/integration_tests/retrievers/test_contextual_compression.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pytest
21
from langchain.retrievers.contextual_compression import ContextualCompressionRetriever
32
from langchain.retrievers.document_compressors import EmbeddingsFilter
43

@@ -27,7 +26,6 @@ def test_contextual_compression_retriever_get_relevant_docs() -> None:
2726
assert texts[-1] not in [d.page_content for d in actual]
2827

2928

30-
@pytest.mark.asyncio
3129
async def test_acontextual_compression_retriever_get_relevant_docs() -> None:
3230
"""Test get_relevant_docs."""
3331
texts = [

libs/community/tests/integration_tests/storage/test_sql.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def test_mget(sql_engine: Engine) -> None:
4545
assert result == [b"value1", b"value2"]
4646

4747

48-
@pytest.mark.asyncio
4948
async def test_amget(sql_aengine: AsyncEngine) -> None:
5049
"""Test mget method."""
5150
store = SQLStore(engine=sql_aengine, namespace="test")
@@ -85,7 +84,6 @@ def test_mset(sql_engine: Engine) -> None:
8584
session.commit()
8685

8786

88-
@pytest.mark.asyncio
8987
async def test_amset(sql_aengine: AsyncEngine) -> None:
9088
"""Test that multiple keys can be set."""
9189
store = SQLStore(engine=sql_aengine, namespace="test")
@@ -131,7 +129,6 @@ def test_mdelete(sql_engine: Engine) -> None:
131129
session.commit()
132130

133131

134-
@pytest.mark.asyncio
135132
async def test_amdelete(sql_aengine: AsyncEngine) -> None:
136133
"""Test that deletion works as expected."""
137134
store = SQLStore(engine=sql_aengine, namespace="test")
@@ -172,7 +169,6 @@ def test_yield_keys(sql_engine: Engine) -> None:
172169
assert sorted(store.yield_keys(prefix="lang")) == []
173170

174171

175-
@pytest.mark.asyncio
176172
async def test_ayield_keys(sql_aengine: AsyncEngine) -> None:
177173
store = SQLStore(engine=sql_aengine, namespace="test")
178174
await store.acreate_schema()

libs/community/tests/integration_tests/vectorstores/test_upstash.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def test_upstash_simple_insert() -> None:
6868

6969

7070
@pytest.mark.vcr()
71-
@pytest.mark.asyncio
7271
async def test_upstash_simple_insert_async() -> None:
7372
"""Test end to end construction and search."""
7473
texts = ["foo", "bar", "baz"]
@@ -94,7 +93,6 @@ def test_upstash_with_metadatas() -> None:
9493

9594

9695
@pytest.mark.vcr()
97-
@pytest.mark.asyncio
9896
async def test_upstash_with_metadatas_async() -> None:
9997
"""Test end to end construction and search."""
10098
texts = ["foo", "bar", "baz"]
@@ -125,7 +123,6 @@ def test_upstash_with_metadatas_with_scores() -> None:
125123

126124

127125
@pytest.mark.vcr()
128-
@pytest.mark.asyncio
129126
async def test_upstash_with_metadatas_with_scores_async() -> None:
130127
"""Test end to end construction and scored search."""
131128
texts = ["foo", "bar", "baz"]
@@ -159,7 +156,6 @@ def test_upstash_with_metadatas_with_scores_using_vector() -> None:
159156

160157

161158
@pytest.mark.vcr()
162-
@pytest.mark.asyncio
163159
async def test_upstash_with_metadatas_with_scores_using_vector_async() -> None:
164160
"""Test end to end construction and scored search, using embedding vector."""
165161
texts = ["foo", "bar", "baz"]
@@ -190,7 +186,6 @@ def test_upstash_mmr() -> None:
190186

191187

192188
@pytest.mark.vcr()
193-
@pytest.mark.asyncio
194189
async def test_upstash_mmr_async() -> None:
195190
"""Test end to end construction and search."""
196191
texts = ["foo", "bar", "baz"]
@@ -213,7 +208,6 @@ def test_upstash_mmr_by_vector() -> None:
213208

214209

215210
@pytest.mark.vcr()
216-
@pytest.mark.asyncio
217211
async def test_upstash_mmr_by_vector_async() -> None:
218212
"""Test end to end construction and search."""
219213
texts = ["foo", "bar", "baz"]
@@ -237,7 +231,6 @@ def test_init_from_index() -> None:
237231

238232

239233
@pytest.mark.vcr()
240-
@pytest.mark.asyncio
241234
async def test_init_from_async_index() -> None:
242235
from upstash_vector import AsyncIndex
243236

@@ -259,7 +252,6 @@ def test_init_from_credentials() -> None:
259252

260253

261254
@pytest.mark.vcr()
262-
@pytest.mark.asyncio
263255
async def test_init_from_credentials_async() -> None:
264256
store = UpstashVectorStore(
265257
index_url=os.environ["UPSTASH_VECTOR_REST_URL"],
@@ -326,7 +318,6 @@ def test_upstash_similarity_search_with_metadata() -> None:
326318

327319

328320
@pytest.mark.vcr()
329-
@pytest.mark.asyncio
330321
async def test_upstash_similarity_search_with_metadata_async() -> None:
331322
store = UpstashVectorStore(embedding=FakeEmbeddings())
332323
docs = [
@@ -384,7 +375,6 @@ def test_upstash_similarity_search_by_vector_with_metadata() -> None:
384375

385376

386377
@pytest.mark.vcr()
387-
@pytest.mark.asyncio
388378
async def test_upstash_similarity_search_by_vector_with_metadata_async() -> None:
389379
store = UpstashVectorStore(embedding=FakeEmbeddings())
390380
docs = [
@@ -434,7 +424,6 @@ def test_upstash_max_marginal_relevance_search_with_metadata() -> None:
434424

435425

436426
@pytest.mark.vcr()
437-
@pytest.mark.asyncio
438427
async def test_upstash_max_marginal_relevance_search_with_metadata_async() -> None:
439428
store = UpstashVectorStore(embedding=FakeEmbeddings())
440429
docs = [
@@ -539,7 +528,6 @@ def test_embedding_index() -> None:
539528

540529

541530
@pytest.mark.vcr()
542-
@pytest.mark.asyncio
543531
async def test_embedding_index_async() -> None:
544532
store = UpstashVectorStore(
545533
index_url=os.environ["UPSTASH_VECTOR_URL_EMBEDDING"],

libs/community/tests/unit_tests/embeddings/test_infinity_local.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515
@pytest.mark.skipif(not IMPORTED_TORCH, reason="torch not installed")
16-
@pytest.mark.asyncio
1716
async def test_local_infinity_embeddings() -> None:
1817
embedder = InfinityEmbeddingsLocal(
1918
model="TaylorAI/bge-micro-v2",

libs/community/tests/unit_tests/llms/test_bedrock.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ async def async_gen_mock_streaming_response() -> AsyncGenerator[Dict, None]:
273273
yield item
274274

275275

276-
@pytest.mark.asyncio
277276
async def test_bedrock_async_streaming_call() -> None:
278277
# Mock boto3 import
279278
mock_boto3 = MagicMock()

libs/community/tests/unit_tests/retrievers/test_you.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from unittest.mock import AsyncMock, patch
22

3-
import pytest
43
import responses
54

65
from langchain_community.retrievers.you import YouRetriever
@@ -63,7 +62,6 @@ def test_invoke_news(self) -> None:
6362
expected_result = NEWS_RESPONSE_PARSED
6463
assert results == expected_result
6564

66-
@pytest.mark.asyncio
6765
async def test_ainvoke(self) -> None:
6866
instance = YouRetriever(ydc_api_key="test_api_key")
6967

libs/community/tests/unit_tests/tools/test_you.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from unittest.mock import AsyncMock, patch
22

3-
import pytest
43
import responses
54

65
from langchain_community.tools.you import YouSearchTool
@@ -68,7 +67,6 @@ def test_invoke_news(self) -> None:
6867
expected_result = NEWS_RESPONSE_PARSED
6968
assert results == expected_result
7069

71-
@pytest.mark.asyncio
7270
async def test_ainvoke(self) -> None:
7371
you_tool = YouSearchTool(api_wrapper=YouSearchAPIWrapper(ydc_api_key="test")) # type: ignore[call-arg]
7472

libs/community/tests/unit_tests/utilities/test_you.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from typing import Any, Dict, List, Optional, Union
22
from unittest.mock import AsyncMock, patch
33

4-
import pytest
54
import responses
65
from langchain_core.documents import Document
76

@@ -189,7 +188,6 @@ def test_results_news() -> None:
189188
assert raw_results == expected_result
190189

191190

192-
@pytest.mark.asyncio
193191
async def test_raw_results_async() -> None:
194192
instance = YouSearchAPIWrapper(ydc_api_key="test_api_key")
195193

@@ -208,7 +206,6 @@ async def test_raw_results_async() -> None:
208206
assert results == MOCK_RESPONSE_RAW
209207

210208

211-
@pytest.mark.asyncio
212209
async def test_results_async() -> None:
213210
instance = YouSearchAPIWrapper(ydc_api_key="test_api_key")
214211

@@ -227,7 +224,6 @@ async def test_results_async() -> None:
227224
assert results == MOCK_PARSED_OUTPUT
228225

229226

230-
@pytest.mark.asyncio
231227
async def test_results_news_async() -> None:
232228
instance = YouSearchAPIWrapper(endpoint_type="news", ydc_api_key="test_api_key")
233229

libs/core/pyproject.toml

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = [ "poetry-core>=1.0.0",]
2+
requires = ["poetry-core>=1.0.0"]
33
build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
@@ -12,10 +12,16 @@ readme = "README.md"
1212
repository = "https://github.com/langchain-ai/langchain"
1313

1414
[tool.mypy]
15-
exclude = [ "notebooks", "examples", "example_data", "langchain_core/pydantic", "tests/unit_tests/utils/test_function_calling.py",]
15+
exclude = [
16+
"notebooks",
17+
"examples",
18+
"example_data",
19+
"langchain_core/pydantic",
20+
"tests/unit_tests/utils/test_function_calling.py",
21+
]
1622
disallow_untyped_defs = "True"
1723
[[tool.mypy.overrides]]
18-
module = [ "numpy", "pytest",]
24+
module = ["numpy", "pytest"]
1925
ignore_missing_imports = true
2026

2127
[tool.ruff]
@@ -73,22 +79,27 @@ select = [
7379
"TID",
7480
"UP",
7581
"W",
76-
"YTT"
82+
"YTT",
7783
]
7884
ignore = [
7985
"COM812", # Messes with the formatter
80-
"UP007", # Incompatible with pydantic + Python 3.9
81-
"W293", #
86+
"UP007", # Incompatible with pydantic + Python 3.9
87+
"W293", #
8288
]
8389

8490
[tool.coverage.run]
85-
omit = [ "tests/*",]
91+
omit = ["tests/*"]
8692

8793
[tool.pytest.ini_options]
8894
addopts = "--snapshot-warn-unused --strict-markers --strict-config --durations=5"
89-
markers = [ "requires: mark tests as requiring a specific library", "asyncio: mark tests as requiring asyncio", "compile: mark placeholder test used to compile integration tests without running them",]
95+
markers = [
96+
"requires: mark tests as requiring a specific library",
97+
"compile: mark placeholder test used to compile integration tests without running them",
98+
]
9099
asyncio_mode = "auto"
91-
filterwarnings = [ "ignore::langchain_core._api.beta_decorator.LangChainBetaWarning",]
100+
filterwarnings = [
101+
"ignore::langchain_core._api.beta_decorator.LangChainBetaWarning",
102+
]
92103

93104
[tool.poetry.group.lint]
94105
optional = true
@@ -106,12 +117,17 @@ optional = true
106117
optional = true
107118

108119
[tool.ruff.lint.pep8-naming]
109-
classmethod-decorators = [ "classmethod", "langchain_core.utils.pydantic.pre_init", "pydantic.field_validator", "pydantic.v1.root_validator",]
120+
classmethod-decorators = [
121+
"classmethod",
122+
"langchain_core.utils.pydantic.pre_init",
123+
"pydantic.field_validator",
124+
"pydantic.v1.root_validator",
125+
]
110126

111127
[tool.ruff.lint.per-file-ignores]
112-
"tests/unit_tests/prompts/test_chat.py" = [ "E501",]
113-
"tests/unit_tests/runnables/test_runnable.py" = [ "E501",]
114-
"tests/unit_tests/runnables/test_graph.py" = [ "E501",]
128+
"tests/unit_tests/prompts/test_chat.py" = ["E501"]
129+
"tests/unit_tests/runnables/test_runnable.py" = ["E501"]
130+
"tests/unit_tests/runnables/test_graph.py" = ["E501"]
115131

116132
[tool.poetry.group.lint.dependencies]
117133
ruff = "^0.5"

libs/core/tests/unit_tests/_api/test_beta_decorator.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ def test_beta_function() -> None:
118118
assert not inspect.iscoroutinefunction(beta_function)
119119

120120

121-
@pytest.mark.asyncio
122121
async def test_beta_async_function() -> None:
123122
"""Test beta async function."""
124123
with warnings.catch_warnings(record=True) as warning_list:
@@ -159,7 +158,6 @@ def test_beta_method() -> None:
159158
assert not inspect.iscoroutinefunction(obj.beta_method)
160159

161160

162-
@pytest.mark.asyncio
163161
async def test_beta_async_method() -> None:
164162
"""Test beta method."""
165163
with warnings.catch_warnings(record=True) as warning_list:

0 commit comments

Comments
 (0)