Sadeep Sachintha commited on
Commit ·
110c66e
1
Parent(s): 5dced34
Mock model loading in tests to fix 404 error
Browse files- tests/test_api.py +7 -2
tests/test_api.py
CHANGED
|
@@ -1,11 +1,16 @@
|
|
| 1 |
from fastapi.testclient import TestClient
|
| 2 |
from app.main import app
|
| 3 |
import pytest
|
|
|
|
| 4 |
|
| 5 |
@pytest.fixture(scope="module")
|
| 6 |
def client():
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def test_read_root(client):
|
| 11 |
response = client.get("/")
|
|
|
|
| 1 |
from fastapi.testclient import TestClient
|
| 2 |
from app.main import app
|
| 3 |
import pytest
|
| 4 |
+
from unittest.mock import patch
|
| 5 |
|
| 6 |
@pytest.fixture(scope="module")
|
| 7 |
def client():
|
| 8 |
+
# Mock the model loading and prediction during tests
|
| 9 |
+
with patch('app.main.load_model'):
|
| 10 |
+
with patch('app.main.predict_sentiment') as mock_predict:
|
| 11 |
+
mock_predict.return_value = {"label": "POSITIVE", "score": 0.95}
|
| 12 |
+
with TestClient(app) as c:
|
| 13 |
+
yield c
|
| 14 |
|
| 15 |
def test_read_root(client):
|
| 16 |
response = client.get("/")
|