File tree Expand file tree Collapse file tree 1 file changed +6
-13
lines changed
Expand file tree Collapse file tree 1 file changed +6
-13
lines changed Original file line number Diff line number Diff line change 1- import os
2- import sys
31from unittest .mock import MagicMock , patch
2+ import sys
3+ import os
44
5- # Add src to sys.path for imports
65sys .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
1716mock_model = MagicMock ()
1817mock_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
2623client = 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 ()
You can’t perform that action at this time.
0 commit comments