Skip to content

Commit 23ead53

Browse files
committed
better conftest
1 parent 6d401d2 commit 23ead53

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

tests/unit/conftest.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
from yarl import URL
1212

1313
from crawlee import service_locator
14-
from crawlee.configuration import Configuration
15-
from crawlee.events._local_event_manager import LocalEventManager
1614
from crawlee.memory_storage_client import MemoryStorageClient
1715
from crawlee.proxy_configuration import ProxyInfo
1816
from crawlee.storages import _creation_management
@@ -38,25 +36,20 @@ def prepare_test_env(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Callabl
3836
"""
3937

4038
def _prepare_test_env() -> None:
41-
# Reset the flags in the service locator to indicate that no services are explicitly set. This ensures
42-
# a clean state, as services might have been set during a previous test and not reset properly.
43-
service_locator._service_locator._configuration_was_set = False
44-
service_locator._service_locator._storage_client_was_set = False
45-
service_locator._service_locator._event_manager_was_set = False
46-
4739
# Set the environment variable for the local storage directory to the temporary path.
4840
monkeypatch.setenv('CRAWLEE_STORAGE_DIR', str(tmp_path))
4941

50-
# Initialize services in the service container with default values.
51-
service_locator.set_configuration(Configuration())
52-
service_locator.set_storage_client(MemoryStorageClient())
53-
service_locator.set_event_manager(LocalEventManager())
54-
55-
# Reset the global state flags in the service locator.
42+
# Reset the flags in the service locator to indicate that no services are explicitly set. This ensures
43+
# a clean state, as services might have been set during a previous test and not reset properly.
5644
service_locator._service_locator._configuration_was_set = False
5745
service_locator._service_locator._storage_client_was_set = False
5846
service_locator._service_locator._event_manager_was_set = False
5947

48+
# Reset the services in the service locator.
49+
service_locator._service_locator._configuration = None
50+
service_locator._service_locator._event_manager = None
51+
service_locator._service_locator._storage_client = None
52+
6053
# Clear creation-related caches to ensure no state is carried over between tests.
6154
monkeypatch.setattr(_creation_management, '_cache_dataset_by_id', {})
6255
monkeypatch.setattr(_creation_management, '_cache_dataset_by_name', {})

0 commit comments

Comments
 (0)