Skip to content

Commit f088726

Browse files
committed
let's keep only prepare_test_env fixture
1 parent dbaf45f commit f088726

File tree

1 file changed

+8
-31
lines changed

1 file changed

+8
-31
lines changed

tests/unit/conftest.py

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from crawlee.storages import _creation_management
1919

2020
if TYPE_CHECKING:
21-
from collections.abc import AsyncGenerator, Generator
21+
from collections.abc import AsyncGenerator
2222
from pathlib import Path
2323

2424

@@ -38,6 +38,12 @@ def prepare_test_env(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Callabl
3838
"""
3939

4040
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+
4147
# Set the environment variable for the local storage directory to the temporary path.
4248
monkeypatch.setenv('CRAWLEE_STORAGE_DIR', str(tmp_path))
4349

@@ -68,46 +74,17 @@ def _prepare_test_env() -> None:
6874
return _prepare_test_env
6975

7076

71-
@pytest.fixture
72-
def cleanup_test_env() -> Callable[[], None]:
73-
"""Clean up and reset global state after a test has completed.
74-
75-
This fixture ensures that any modifications to the global state during a test are undone
76-
after the test finishes. Restoring the environment for the subsequent tests.
77-
78-
Returns:
79-
A callable that cleans up the test environment.
80-
"""
81-
82-
def _cleanup_test_env() -> None:
83-
# Reset the flags in the service locator to indicate no services are explicitly set.
84-
service_locator._service_locator._configuration_was_set = False
85-
service_locator._service_locator._storage_client_was_set = False
86-
service_locator._service_locator._event_manager_was_set = False
87-
88-
return _cleanup_test_env
89-
90-
9177
@pytest.fixture(autouse=True)
92-
def _isolate_test_environment(
93-
prepare_test_env: Callable[[], None],
94-
cleanup_test_env: Callable[[], None],
95-
) -> Generator[None, None, None]:
78+
def _isolate_test_environment(prepare_test_env: Callable[[], None]) -> None:
9679
"""Isolate the testing environment by resetting global state before and after each test.
9780
9881
This fixture ensures that each test starts with a clean slate and that any modifications during the test
9982
do not affect subsequent tests. It runs automatically for all tests.
10083
10184
Args:
10285
prepare_test_env: Fixture to prepare the environment before each test.
103-
cleanup_test_env: Fixture to clean up the environment after each test.
104-
105-
Yields:
106-
None. This fixture works as a setup and teardown mechanism.
10786
"""
10887
prepare_test_env()
109-
yield
110-
cleanup_test_env()
11188

11289

11390
@pytest.fixture

0 commit comments

Comments
 (0)