Skip to content

Commit 3266c10

Browse files
committed
Add FastAPI app with Docker, CI/CD, and linter checking flake8 and pytest
1 parent 90efae1 commit 3266c10

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

test/test_api.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
import os
22
import sys
3-
from unittest.mock import MagicMock, patch
4-
from fastapi.testclient import TestClient
5-
from api.main import app
3+
from unittest.mock import patch
4+
from unittest.mock import MagicMock
65

7-
# Add src to sys.path for imports
6+
# Add root to sys.path for imports
87
sys.path.insert(
9-
0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src'))
8+
0,
9+
os.path.abspath(
10+
os.path.join(
11+
os.path.dirname(__file__),
12+
'..',
13+
)
14+
),
1015
)
1116

12-
# --- Patch before importing app ---
17+
1318
mock_model = MagicMock()
1419
mock_model.predict_proba.return_value = [[0.3, 0.7]]
1520

1621
patcher = patch('mlflow.sklearn.load_model', return_value=mock_model)
1722
patcher.start()
23+
24+
from fastapi.testclient import TestClient # noqa: E402
25+
from api.main import app # noqa: E402
26+
1827
client = TestClient(app)
1928

2029

0 commit comments

Comments
 (0)