Skip to content

Commit 9ded640

Browse files
committed
✅ Isolate tests from config
Shortcake-Parent: main
1 parent fae7dee commit 9ded640

File tree

11 files changed

+140
-113
lines changed

11 files changed

+140
-113
lines changed

tests/conftest.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
1+
import os
12
import sys
3+
import tempfile
24
from collections.abc import Generator
35
from dataclasses import dataclass
46
from pathlib import Path
5-
from unittest.mock import patch
67

78
import pytest
9+
import respx
810
from typer import rich_utils
911

12+
from fastapi_cloud_cli.config import Settings
13+
from fastapi_cloud_cli.utils.config import CONFIG_DIR_ENV_VAR
14+
1015
from .utils import create_jwt_token
1116

1217

18+
@pytest.fixture(autouse=True)
19+
def isolated_config_path() -> Generator[Path, None, None]:
20+
with tempfile.TemporaryDirectory() as tmpdir:
21+
os.environ[CONFIG_DIR_ENV_VAR] = tmpdir
22+
23+
yield Path(tmpdir)
24+
25+
26+
@pytest.fixture
27+
def temp_auth_config(
28+
isolated_config_path: Path, monkeypatch: pytest.MonkeyPatch
29+
) -> Generator[Path, None, None]:
30+
yield isolated_config_path / "auth.json"
31+
32+
1333
@pytest.fixture(autouse=True)
1434
def reset_syspath() -> Generator[None, None, None]:
1535
initial_python_path = sys.path.copy()
@@ -26,6 +46,17 @@ def setup_terminal() -> None:
2646
return
2747

2848

49+
@pytest.fixture
50+
def settings() -> Settings:
51+
return Settings.get()
52+
53+
54+
@pytest.fixture
55+
def respx_mock(settings: Settings) -> Generator[respx.MockRouter, None, None]:
56+
with respx.mock(base_url=settings.base_api_url) as mock_router:
57+
yield mock_router
58+
59+
2960
@pytest.fixture
3061
def logged_in_cli(temp_auth_config: Path) -> Generator[None, None, None]:
3162
valid_token = create_jwt_token({"sub": "test_user_12345"})
@@ -60,13 +91,3 @@ def configured_app(tmp_path: Path) -> ConfiguredApp:
6091
config_path.write_text(f'{{"app_id": "{app_id}", "team_id": "{team_id}"}}')
6192

6293
return ConfiguredApp(app_id=app_id, team_id=team_id, path=tmp_path)
63-
64-
65-
@pytest.fixture
66-
def temp_auth_config(tmp_path: Path) -> Generator[Path, None, None]:
67-
"""Provides a temporary auth config setup for testing file operations."""
68-
69-
with patch(
70-
"fastapi_cloud_cli.utils.config.get_config_folder", return_value=tmp_path
71-
):
72-
yield tmp_path / "auth.json"

tests/test_api_client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
)
1818
from tests.utils import build_logs_response
1919

20-
settings = Settings.get()
21-
2220

2321
@pytest.fixture
2422
def client() -> httpx.Client:
@@ -31,7 +29,7 @@ def deployment_id() -> str:
3129
return "test-deployment-123"
3230

3331

34-
api_mock = respx.mock(base_url=settings.base_api_url)
32+
api_mock = respx.mock(base_url=Settings().base_api_url)
3533

3634

3735
@pytest.fixture
@@ -284,7 +282,7 @@ def test_stream_build_logs_empty_lines_are_skipped(
284282
assert logs[1].type == "complete"
285283

286284

287-
@respx.mock(base_url=settings.base_api_url)
285+
@respx.mock(base_url=Settings().base_api_url)
288286
def test_stream_build_logs_continue_after_timeout(
289287
respx_mock: respx.MockRouter,
290288
client: APIClient,

0 commit comments

Comments
 (0)