Skip to content

Commit 8731aff

Browse files
committed
Fix unit tests
1 parent c77e8d5 commit 8731aff

12 files changed

+42
-41
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ type-check:
2626
uv run mypy
2727

2828
unit-tests:
29-
uv run pytest --numprocesses=auto --verbose --cov=src/apify tests/unit
29+
uv run pytest --numprocesses=auto -vv --cov=src/apify tests/unit
3030

3131
unit-tests-cov:
32-
uv run pytest --numprocesses=auto --verbose --cov=src/apify --cov-report=html tests/unit
32+
uv run pytest --numprocesses=auto -vv --cov=src/apify --cov-report=html tests/unit
3333

3434
integration-tests:
35-
uv run pytest --numprocesses=$(INTEGRATION_TESTS_CONCURRENCY) --verbose tests/integration
35+
uv run pytest --numprocesses=$(INTEGRATION_TESTS_CONCURRENCY) -vv tests/integration
3636

3737
format:
3838
uv run ruff check --fix

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies = [
3737
"apify-client>=1.11.0",
3838
"apify-shared>=1.3.0",
3939
"cachetools>=5.5.0",
40-
"crawlee@git+https://github.com/apify/crawlee-python.git@1cbf15e13af882c864b87f8ed48252bcb3747993",
40+
"crawlee@git+https://github.com/apify/crawlee-python.git@new-storage-clients",
4141
"cryptography>=42.0.0",
4242
"httpx>=0.27.0",
4343
# TODO: ensure compatibility with the latest version of lazy-object-proxy

src/apify/_actor.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,23 @@ def get_env(self) -> dict:
682682
config[alias] = getattr(self._configuration, field_name)
683683

684684
env_vars = {env_var.value.lower(): env_var.name.lower() for env_var in [*ActorEnvVars, *ApifyEnvVars]}
685-
return {option_name: config[env_var] for env_var, option_name in env_vars.items() if env_var in config}
685+
result = {option_name: config[env_var] for env_var, option_name in env_vars.items() if env_var in config}
686+
687+
# These environment variables are not part of the Configuration model,
688+
# so we need to add them manually to the result dictionary.
689+
result[ActorEnvVars.DEFAULT_DATASET_ID.name.lower()] = os.environ.get(
690+
ActorEnvVars.DEFAULT_DATASET_ID.value
691+
) or os.environ.get(ApifyEnvVars.DEFAULT_DATASET_ID.value)
692+
693+
result[ActorEnvVars.DEFAULT_KEY_VALUE_STORE_ID.name.lower()] = os.environ.get(
694+
ActorEnvVars.DEFAULT_KEY_VALUE_STORE_ID.value
695+
) or os.environ.get(ApifyEnvVars.DEFAULT_KEY_VALUE_STORE_ID.value)
696+
697+
result[ActorEnvVars.DEFAULT_REQUEST_QUEUE_ID.name.lower()] = os.environ.get(
698+
ActorEnvVars.DEFAULT_REQUEST_QUEUE_ID.value
699+
) or os.environ.get(ApifyEnvVars.DEFAULT_REQUEST_QUEUE_ID.value)
700+
701+
return result
686702

687703
async def start(
688704
self,

src/apify/storage_clients/_apify/_dataset_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing_extensions import override
99

1010
from apify_client import ApifyClientAsync
11+
from apify_shared.consts import ActorEnvVars, ApifyEnvVars
1112
from crawlee.storage_clients._base import DatasetClient
1213
from crawlee.storage_clients.models import DatasetItemsListPage, DatasetMetadata
1314

@@ -99,10 +100,10 @@ async def open(
99100
# If both id and name are None, try to get the default storage ID from environment variables.
100101
if id is None and name is None:
101102
id = os.environ.get(
102-
'ACTOR_DEFAULT_DATASET_ID',
103+
ActorEnvVars.DEFAULT_DATASET_ID.value,
103104
None,
104105
) or os.environ.get(
105-
'APIFY_DEFAULT_DATASET_ID',
106+
ApifyEnvVars.DEFAULT_DATASET_ID.value,
106107
None,
107108
)
108109

src/apify/storage_clients/_apify/_key_value_store_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from yarl import URL
1010

1111
from apify_client import ApifyClientAsync
12+
from apify_shared.consts import ActorEnvVars, ApifyEnvVars
1213
from crawlee.storage_clients._base import KeyValueStoreClient
1314
from crawlee.storage_clients.models import KeyValueStoreMetadata, KeyValueStoreRecord, KeyValueStoreRecordMetadata
1415

@@ -101,10 +102,10 @@ async def open(
101102
# If both id and name are None, try to get the default storage ID from environment variables.
102103
if id is None and name is None:
103104
id = os.environ.get(
104-
'ACTOR_DEFAULT_KEY_VALUE_STORE_ID',
105+
ActorEnvVars.DEFAULT_KEY_VALUE_STORE_ID.value,
105106
None,
106107
) or os.environ.get(
107-
'APIFY_DEFAULT_KEY_VALUE_STORE_ID',
108+
ApifyEnvVars.DEFAULT_KEY_VALUE_STORE_ID.value,
108109
None,
109110
)
110111

src/apify/storage_clients/_apify/_request_queue_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing_extensions import override
1212

1313
from apify_client import ApifyClientAsync
14+
from apify_shared.consts import ActorEnvVars, ApifyEnvVars
1415
from crawlee._utils.requests import unique_key_to_request_id
1516
from crawlee.storage_clients._base import RequestQueueClient
1617
from crawlee.storage_clients.models import AddRequestsResponse, ProcessedRequest, RequestQueueMetadata
@@ -131,10 +132,10 @@ async def open(
131132
# If both id and name are None, try to get the default storage ID from environment variables.
132133
if id is None and name is None:
133134
id = os.environ.get(
134-
'ACTOR_DEFAULT_REQUEST_QUEUE_ID',
135+
ActorEnvVars.DEFAULT_REQUEST_QUEUE_ID.value,
135136
None,
136137
) or os.environ.get(
137-
'APIFY_DEFAULT_REQUEST_QUEUE_ID',
138+
ApifyEnvVars.DEFAULT_REQUEST_QUEUE_ID.value,
138139
None,
139140
)
140141

tests/integration/test_actor_dataset.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ async def main() -> None:
3737
assert len(list_page.items) == list_page.count == desired_item_count
3838

3939

40+
import pytest
41+
42+
43+
@pytest.mark.only
4044
async def test_push_large_data_chunks_over_9mb(
4145
make_actor: MakeActorFunction,
4246
run_actor: RunActorFunction,

tests/unit/actor/test_actor_dataset.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@
22

33
import pytest
44

5-
from apify_shared.consts import ActorEnvVars
6-
from crawlee.storage_clients import FileSystemStorageClient
7-
85
from apify import Actor
96

10-
# NOTE: We only test the dataset methods available on Actor class/instance.
11-
# Actual tests for the implementations are in storages/.
12-
137

148
async def test_throws_error_without_actor_init() -> None:
159
with pytest.raises(RuntimeError):
@@ -34,20 +28,6 @@ async def test_open_dataset_returns_same_references() -> None:
3428
assert dataset_by_id_2 is dataset_by_id_1
3529

3630

37-
@pytest.mark.skip(reason='TODO: fix this test')
38-
async def test_open_dataset_uses_env_var(monkeypatch: pytest.MonkeyPatch) -> None:
39-
memory_storage_client = FileSystemStorageClient()
40-
41-
default_dataset_id = 'my-new-default-id'
42-
monkeypatch.setenv(ActorEnvVars.DEFAULT_DATASET_ID, default_dataset_id)
43-
44-
async with Actor:
45-
ddt = await Actor.open_dataset()
46-
assert ddt.metadata.id == default_dataset_id
47-
dataset = await memory_storage_client.create_dataset_client(id=ddt.metadata.id)
48-
await dataset.drop()
49-
50-
5131
async def test_push_data_to_dataset() -> None:
5232
async with Actor as actor:
5333
dataset = await actor.open_dataset()

tests/unit/actor/test_actor_env_helpers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
import string
55
from datetime import datetime, timedelta
66
from decimal import Decimal
7-
from typing import Any
7+
from typing import TYPE_CHECKING, Any
88

9-
import pytest
109
from pydantic_core import TzInfo
1110

1211
from apify_shared.consts import (
@@ -22,14 +21,16 @@
2221

2322
from apify import Actor
2423

24+
if TYPE_CHECKING:
25+
import pytest
26+
2527

2628
async def test_actor_is_not_at_home_when_local() -> None:
2729
async with Actor as actor:
2830
is_at_home = actor.is_at_home()
2931
assert is_at_home is False
3032

3133

32-
@pytest.mark.skip(reason='TODO: fix this test')
3334
async def test_get_env_with_randomized_env_vars(monkeypatch: pytest.MonkeyPatch) -> None: # noqa: PLR0912
3435
ignored_env_vars = {
3536
ApifyEnvVars.INPUT_KEY,
@@ -43,6 +44,7 @@ async def test_get_env_with_randomized_env_vars(monkeypatch: pytest.MonkeyPatch)
4344
ApifyEnvVars.LOG_FORMAT,
4445
ApifyEnvVars.LOG_LEVEL,
4546
ActorEnvVars.STANDBY_PORT,
47+
ApifyEnvVars.PERSIST_STORAGE,
4648
}
4749

4850
legacy_env_vars = {
@@ -58,7 +60,7 @@ async def test_get_env_with_randomized_env_vars(monkeypatch: pytest.MonkeyPatch)
5860
}
5961

6062
# Set up random env vars
61-
expected_get_env: dict[str, Any] = {}
63+
expected_get_env = dict[str, Any]()
6264
expected_get_env[ApifyEnvVars.LOG_LEVEL.name.lower()] = 'INFO'
6365

6466
for int_env_var in INTEGER_ENV_VARS:

tests/unit/actor/test_actor_key_value_store.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
from apify._crypto import public_encrypt
1111

1212

13-
# NOTE: We only test the key-value store methods available on Actor class/instance.
14-
# Actual tests for the implementations are in storages/.
1513
async def test_open_returns_same_references() -> None:
1614
async with Actor:
1715
kvs1 = await Actor.open_key_value_store()

0 commit comments

Comments
 (0)