Skip to content

Commit 5c97255

Browse files
committed
Add FastAPI app with Docker, CI/CD, and linter
1 parent d131a45 commit 5c97255

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

test/test_api.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
import os
2-
import sys
31
from unittest.mock import MagicMock, patch
2+
import sys
3+
import os
44

5-
# Add src to sys.path for imports
65
sys.path.insert(
76
0,
87
os.path.abspath(
98
os.path.join(
109
os.path.dirname(__file__),
1110
'..',
12-
'src', # <-- Add 'src' here to point to the source folder
11+
'src',
1312
)
1413
),
1514
)
1615

1716
mock_model = MagicMock()
1817
mock_model.predict_proba.return_value = [[0.3, 0.7]]
1918

20-
patcher = patch('mlflow.sklearn.load_model', return_value=mock_model)
21-
patcher.start()
22-
23-
from fastapi.testclient import TestClient # noqa: E402
24-
from api.main import app # noqa: E402
19+
with patch('mlflow.sklearn.load_model', return_value=mock_model):
20+
from fastapi.testclient import TestClient
21+
from api.main import app
2522

2623
client = TestClient(app)
2724

@@ -60,7 +57,3 @@ def test_predict():
6057
assert response.status_code == 200
6158
assert "risk_probability" in response.json()
6259
assert abs(response.json()["risk_probability"] - 0.7) < 1e-6
63-
64-
65-
# --- Cleanup ---
66-
patcher.stop()

0 commit comments

Comments
 (0)