Skip to content

Commit 79213a3

Browse files
committed
fix: import app inside fixture to avoid collection errors
Move app import inside fixture to prevent module-level import conflicts when running full test suite
1 parent a3716b9 commit 79213a3

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

tests/test_examples/test_bookings.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# ruff: noqa: E402
22
"""Tests for the bookings example."""
33

4-
import importlib
54
import sys
65
from pathlib import Path
76

@@ -14,27 +13,21 @@
1413
if example_path_str not in sys.path:
1514
sys.path.insert(0, example_path_str)
1615

17-
# Import app - reload to avoid caching issues
18-
if "main" in sys.modules:
19-
importlib.reload(sys.modules["main"])
20-
from main import app # noqa: E402
21-
2216
CPO_BASE_URL = "/ocpi/cpo/2.3.0/bookings"
2317
# Base64-encoded token for OCPI 2.3.0 (my-cpo-token-123)
2418
AUTH_HEADER = {"Authorization": "Token bXktY3BvLXRva2VuLTEyMw=="}
2519

2620

27-
@pytest.fixture
21+
@pytest.fixture(scope="function")
2822
def client():
29-
"""Create test client."""
30-
# Clear storage between tests
31-
# Reload crud module to ensure fresh state
32-
if "crud" in sys.modules:
33-
importlib.reload(sys.modules["crud"])
23+
"""Create test client with isolated storage."""
24+
# Import here to avoid module-level import issues
25+
import main # noqa: E402
3426
import crud # noqa: E402
3527

28+
# Clear storage before each test
3629
crud.bookings_storage.clear()
37-
return TestClient(app)
30+
return TestClient(main.app)
3831

3932

4033
@pytest.fixture

0 commit comments

Comments
 (0)