Skip to content

Commit a23ce8b

Browse files
authored
chore: Resolve some warnings in tests (#1442)
``` D:\a\crawlee-python\crawlee-python\tests\unit\storages\test_key_value_store.py:1073: UserWarning: The SqlStorageClient is experimental and may change or be removed in future releases. pytest.param(SqlStorageClient(), id='tested=SqlStorageClient'), ``` - `suppress_user_warning` fixture has autouse ``` tests/unit/crawlers/_basic/test_basic_crawler.py::test_status_message_callback D:\a\crawlee-python\crawlee-python\tests\unit\crawlers\_basic\test_basic_crawler.py:1507: RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited status_message_callback(message) Enable tracemalloc to get traceback where the object was allocated. See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info. ``` - added missing await
1 parent 051272d commit a23ce8b

File tree

6 files changed

+7
-22
lines changed

6 files changed

+7
-22
lines changed

tests/unit/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@
2929
from crawlee.http_clients._base import HttpClient
3030

3131

32-
@pytest.fixture
32+
@pytest.fixture(autouse=True)
3333
async def suppress_user_warning() -> AsyncGenerator[None, None]:
34-
"""Suppress user warnings during tests."""
34+
"""Suppress user warnings during tests.
35+
36+
Mostly to suppress warnings about the experimental status of the SqlStorageClient.
37+
"""
3538
with warnings.catch_warnings():
3639
warnings.simplefilter('ignore', UserWarning)
3740
yield

tests/unit/crawlers/_basic/test_basic_crawler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ async def test_status_message_callback() -> None:
15041504
async def status_callback(
15051505
state: StatisticsState, previous_state: StatisticsState | None, message: str
15061506
) -> str | None:
1507-
status_message_callback(message)
1507+
await status_message_callback(message)
15081508
states.append({'state': state, 'previous_state': previous_state})
15091509
return message
15101510

tests/unit/storage_clients/_sql/test_sql_dataset_client.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def get_tables(sync_conn: Connection) -> list[str]:
3939
async def dataset_client(
4040
configuration: Configuration,
4141
monkeypatch: pytest.MonkeyPatch,
42-
suppress_user_warning: None, # noqa: ARG001
4342
) -> AsyncGenerator[SqlDatasetClient, None]:
4443
"""A fixture for a SQL dataset client."""
4544
async with SqlStorageClient() as storage_client:
@@ -52,7 +51,6 @@ async def dataset_client(
5251
await client.drop()
5352

5453

55-
@pytest.mark.usefixtures('suppress_user_warning')
5654
async def test_create_tables_with_connection_string(configuration: Configuration, tmp_path: Path) -> None:
5755
"""Test that SQL dataset client creates tables with a connection string."""
5856
storage_dir = tmp_path / 'test_table.db'
@@ -69,7 +67,6 @@ async def test_create_tables_with_connection_string(configuration: Configuration
6967
assert 'datasets' in tables
7068

7169

72-
@pytest.mark.usefixtures('suppress_user_warning')
7370
async def test_create_tables_with_engine(configuration: Configuration, tmp_path: Path) -> None:
7471
"""Test that SQL dataset client creates tables with a pre-configured engine."""
7572
storage_dir = tmp_path / 'test_table.db'
@@ -88,7 +85,6 @@ async def test_create_tables_with_engine(configuration: Configuration, tmp_path:
8885
assert 'datasets' in tables
8986

9087

91-
@pytest.mark.usefixtures('suppress_user_warning')
9288
async def test_tables_and_metadata_record(configuration: Configuration) -> None:
9389
"""Test that SQL dataset creates proper tables and metadata records."""
9490
async with SqlStorageClient() as storage_client:
@@ -215,7 +211,6 @@ async def test_metadata_record_updates(dataset_client: SqlDatasetClient) -> None
215211
assert orm_metadata.modified_at == metadata.modified_at
216212

217213

218-
@pytest.mark.usefixtures('suppress_user_warning')
219214
async def test_data_persistence_across_reopens(configuration: Configuration) -> None:
220215
"""Test that data persists correctly when reopening the same dataset."""
221216
async with SqlStorageClient() as storage_client:

tests/unit/storage_clients/_sql/test_sql_kvs_client.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def configuration(tmp_path: Path) -> Configuration:
3535
async def kvs_client(
3636
configuration: Configuration,
3737
monkeypatch: pytest.MonkeyPatch,
38-
suppress_user_warning: None, # noqa: ARG001
3938
) -> AsyncGenerator[SqlKeyValueStoreClient, None]:
4039
"""A fixture for a SQL key-value store client."""
4140
async with SqlStorageClient() as storage_client:
@@ -55,7 +54,6 @@ def get_tables(sync_conn: Connection) -> list[str]:
5554
return inspector.get_table_names()
5655

5756

58-
@pytest.mark.usefixtures('suppress_user_warning')
5957
async def test_create_tables_with_connection_string(configuration: Configuration, tmp_path: Path) -> None:
6058
"""Test that SQL key-value store client creates tables with a connection string."""
6159
storage_dir = tmp_path / 'test_table.db'
@@ -72,7 +70,6 @@ async def test_create_tables_with_connection_string(configuration: Configuration
7270
assert 'key_value_store_records' in tables
7371

7472

75-
@pytest.mark.usefixtures('suppress_user_warning')
7673
async def test_create_tables_with_engine(configuration: Configuration, tmp_path: Path) -> None:
7774
"""Test that SQL key-value store client creates tables with a pre-configured engine."""
7875
storage_dir = tmp_path / 'test_table.db'
@@ -91,7 +88,6 @@ async def test_create_tables_with_engine(configuration: Configuration, tmp_path:
9188
assert 'key_value_store_records' in tables
9289

9390

94-
@pytest.mark.usefixtures('suppress_user_warning')
9591
async def test_tables_and_metadata_record(configuration: Configuration) -> None:
9692
"""Test that SQL key-value store creates proper tables and metadata records."""
9793
async with SqlStorageClient() as storage_client:
@@ -264,7 +260,6 @@ async def test_metadata_record_updates(kvs_client: SqlKeyValueStoreClient) -> No
264260
assert orm_metadata.modified_at == metadata.modified_at
265261

266262

267-
@pytest.mark.usefixtures('suppress_user_warning')
268263
async def test_data_persistence_across_reopens(configuration: Configuration) -> None:
269264
"""Test that data persists correctly when reopening the same key-value store."""
270265
async with SqlStorageClient() as storage_client:

tests/unit/storage_clients/_sql/test_sql_rq_client.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def configuration(tmp_path: Path) -> Configuration:
3636
async def rq_client(
3737
configuration: Configuration,
3838
monkeypatch: pytest.MonkeyPatch,
39-
suppress_user_warning: None, # noqa: ARG001
4039
) -> AsyncGenerator[SqlRequestQueueClient, None]:
4140
"""A fixture for a SQL request queue client."""
4241
async with SqlStorageClient() as storage_client:
@@ -56,7 +55,6 @@ def get_tables(sync_conn: Connection) -> list[str]:
5655
return inspector.get_table_names()
5756

5857

59-
@pytest.mark.usefixtures('suppress_user_warning')
6058
async def test_create_tables_with_connection_string(configuration: Configuration, tmp_path: Path) -> None:
6159
"""Test that SQL request queue client creates tables with a connection string."""
6260
storage_dir = tmp_path / 'test_table.db'
@@ -74,7 +72,6 @@ async def test_create_tables_with_connection_string(configuration: Configuration
7472
assert 'request_queue_state' in tables
7573

7674

77-
@pytest.mark.usefixtures('suppress_user_warning')
7875
async def test_create_tables_with_engine(configuration: Configuration, tmp_path: Path) -> None:
7976
"""Test that SQL request queue client creates tables with a pre-configured engine."""
8077
storage_dir = tmp_path / 'test_table.db'
@@ -94,7 +91,6 @@ async def test_create_tables_with_engine(configuration: Configuration, tmp_path:
9491
assert 'request_queue_state' in tables
9592

9693

97-
@pytest.mark.usefixtures('suppress_user_warning')
9894
async def test_tables_and_metadata_record(configuration: Configuration) -> None:
9995
"""Test that SQL request queue creates proper tables and metadata records."""
10096
async with SqlStorageClient() as storage_client:
@@ -207,7 +203,6 @@ async def test_metadata_record_updates(rq_client: SqlRequestQueueClient) -> None
207203
assert orm_metadata.modified_at == metadata.modified_at
208204

209205

210-
@pytest.mark.usefixtures('suppress_user_warning')
211206
async def test_data_persistence_across_reopens(configuration: Configuration) -> None:
212207
"""Test that data persists correctly when reopening the same request queue."""
213208
async with SqlStorageClient() as storage_client:

tests/unit/storages/conftest.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55

66

77
@pytest.fixture(params=['memory', 'file_system', 'sql'])
8-
def storage_client(
9-
request: pytest.FixtureRequest,
10-
suppress_user_warning: None, # noqa: ARG001
11-
) -> StorageClient:
8+
def storage_client(request: pytest.FixtureRequest) -> StorageClient:
129
"""Parameterized fixture to test with different storage clients."""
1310
storage_client: StorageClient
1411
if request.param == 'memory':

0 commit comments

Comments
 (0)