Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 40ce970

Browse filesBrowse files
committed
Small test improvements
1 parent 770a50e commit 40ce970
Copy full SHA for 40ce970

File tree

Expand file treeCollapse file tree

4 files changed

+29
-27
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+29
-27
lines changed

‎tests/integration/test_actor_key_value_store.py

Copy file name to clipboardExpand all lines: tests/integration/test_actor_key_value_store.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ async def main():
171171
assert run_result['status'] == 'SUCCEEDED'
172172

173173

174-
@pytest.mark.only
175174
class TestGetPublicUrl:
176175
async def test_get_public_url(self, make_actor: ActorFactory) -> None:
177176
async def main() -> None:

‎tests/integration/test_actor_log.py

Copy file name to clipboardExpand all lines: tests/integration/test_actor_log.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from apify import Actor, __version__
2-
from apify_client._version import __version__ as apify_client_version
32

43
from .conftest import ActorFactory
54

@@ -69,7 +68,7 @@ async def main() -> None:
6968
assert run_log_lines.pop(0) == 'ACTOR: Creating Docker container.'
7069
assert run_log_lines.pop(0) == 'ACTOR: Starting Docker container.'
7170
assert run_log_lines.pop(0) == 'INFO Initializing actor...'
72-
assert run_log_lines.pop(0).startswith(f'INFO System info ({{"apify_sdk_version": "{__version__}", "apify_client_version": "{apify_client_version}"') # noqa: E501
71+
assert run_log_lines.pop(0).startswith(f'INFO System info ({{"apify_sdk_version": "{__version__}", "apify_client_version": "')
7372
assert run_log_lines.pop(0) == 'DEBUG Debug message'
7473
assert run_log_lines.pop(0) == 'INFO Info message'
7574
assert run_log_lines.pop(0) == 'WARN Warning message'

‎tests/unit/actor/test_actor_memory_storage_e2e.py

Copy file name to clipboardExpand all lines: tests/unit/actor/test_actor_memory_storage_e2e.py
+10-14Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
from typing import Callable
2+
13
import pytest
24

35
from apify import Actor
4-
from apify.config import Configuration
56
from apify.consts import ApifyEnvVars
6-
from apify.storages import Dataset, KeyValueStore, RequestQueue, StorageClientManager
7+
from apify.storages import StorageClientManager
78

89

910
@pytest.mark.parametrize('purge_on_start', [True, False])
10-
async def test_actor_memory_storage_client_e2e(monkeypatch: pytest.MonkeyPatch, purge_on_start: bool) -> None:
11+
async def test_actor_memory_storage_client_e2e(
12+
monkeypatch: pytest.MonkeyPatch,
13+
purge_on_start: bool,
14+
reset_default_instances: Callable[[], None],
15+
) -> None:
1116
"""This test simulates two clean runs using memory storage.
1217
The second run attempts to access data created by the first one.
1318
We run 2 configurations with different `purge_on_start`."""
@@ -22,19 +27,10 @@ async def test_actor_memory_storage_client_e2e(monkeypatch: pytest.MonkeyPatch,
2227
await old_default_kvs.set_value('test', 'default value')
2328
await old_non_default_kvs.set_value('test', 'non-default value')
2429

25-
# Clean up singletons and mock a new memory storage
26-
monkeypatch.setattr(Actor, '_default_instance', None)
27-
monkeypatch.setattr(Configuration, '_default_instance', None)
28-
monkeypatch.setattr(Dataset, '_cache_by_id', None)
29-
monkeypatch.setattr(Dataset, '_cache_by_name', None)
30-
monkeypatch.setattr(KeyValueStore, '_cache_by_id', None)
31-
monkeypatch.setattr(KeyValueStore, '_cache_by_name', None)
32-
monkeypatch.setattr(RequestQueue, '_cache_by_id', None)
33-
monkeypatch.setattr(RequestQueue, '_cache_by_name', None)
34-
monkeypatch.setattr(StorageClientManager, '_default_instance', None)
35-
3630
# We simulate another clean run, we expect the memory storage to read from the local data directory
3731
# Default storages are purged based on purge_on_start parameter.
32+
reset_default_instances()
33+
3834
async with Actor:
3935
# Check if we're using a different memory storage instance
4036
assert old_client is not StorageClientManager.get_storage_client()

‎tests/unit/conftest.py

Copy file name to clipboardExpand all lines: tests/unit/conftest.py
+18-10Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,27 @@
1414
from apify_client.client import ApifyClientAsync
1515

1616

17+
@pytest.fixture
18+
def reset_default_instances(monkeypatch: pytest.MonkeyPatch) -> Callable[[], None]:
19+
def reset() -> None:
20+
monkeypatch.setattr(Actor, '_default_instance', None)
21+
monkeypatch.setattr(Configuration, '_default_instance', None)
22+
monkeypatch.setattr(Dataset, '_cache_by_id', None)
23+
monkeypatch.setattr(Dataset, '_cache_by_name', None)
24+
monkeypatch.setattr(KeyValueStore, '_cache_by_id', None)
25+
monkeypatch.setattr(KeyValueStore, '_cache_by_name', None)
26+
monkeypatch.setattr(RequestQueue, '_cache_by_id', None)
27+
monkeypatch.setattr(RequestQueue, '_cache_by_name', None)
28+
monkeypatch.setattr(StorageClientManager, '_default_instance', None)
29+
30+
return reset
31+
32+
1733
# To isolate the tests, we need to reset the used singletons before each test case
1834
# We also set the MemoryStorageClient to use a temp path
1935
@pytest.fixture(autouse=True)
20-
def _reset_and_patch_default_instances(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
21-
monkeypatch.setattr(Actor, '_default_instance', None)
22-
monkeypatch.setattr(Configuration, '_default_instance', None)
23-
monkeypatch.setattr(Dataset, '_cache_by_id', None)
24-
monkeypatch.setattr(Dataset, '_cache_by_name', None)
25-
monkeypatch.setattr(KeyValueStore, '_cache_by_id', None)
26-
monkeypatch.setattr(KeyValueStore, '_cache_by_name', None)
27-
monkeypatch.setattr(RequestQueue, '_cache_by_id', None)
28-
monkeypatch.setattr(RequestQueue, '_cache_by_name', None)
29-
monkeypatch.setattr(StorageClientManager, '_default_instance', None)
36+
def _reset_and_patch_default_instances(monkeypatch: pytest.MonkeyPatch, tmp_path: Path, reset_default_instances: Callable[[], None]) -> None:
37+
reset_default_instances()
3038

3139
# This forces the MemoryStorageClient to use tmp_path for its storage dir
3240
monkeypatch.setenv(ApifyEnvVars.LOCAL_STORAGE_DIR, str(tmp_path))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.