File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66pydantic
77flake8
88pytest
9+ httpx
Original file line number Diff line number Diff line change 11import os
22import sys
33from unittest .mock import MagicMock , patch
4- from fastapi .testclient import TestClient
5- from api .main import app # import AFTER patching
64
75# Add src to sys.path for imports
86sys .path .insert (0 , os .path .abspath (os .path .join (
97 os .path .dirname (__file__ ), '..' , 'src' )))
108
11-
12- # Mock mlflow.sklearn.load_model before importing your app
9+ # --- Patch before importing app ---
1310mock_model = MagicMock ()
1411mock_model .predict_proba .return_value = [[0.3 , 0.7 ]]
1512
1613patcher = patch ('mlflow.sklearn.load_model' , return_value = mock_model )
1714patcher .start ()
1815
16+ # Now import app
17+ from fastapi .testclient import TestClient
18+ from api .main import app
1919
2020client = TestClient (app )
2121
22-
22+ # --- Test ---
2323def test_predict ():
2424 sample_data = {
2525 "Recency" : 1 ,
@@ -55,5 +55,5 @@ def test_predict():
5555 assert "risk_probability" in response .json ()
5656 assert abs (response .json ()["risk_probability" ] - 0.7 ) < 1e-6
5757
58-
58+ # --- Cleanup ---
5959patcher .stop ()
You can’t perform that action at this time.
0 commit comments