Skip to content

Commit ade87a6

Browse files
changed tests, added pytest.ini.
1 parent 44346be commit ade87a6

6 files changed

Lines changed: 19 additions & 11 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.venv
22
__pycache__
3-
.ruff_cache
3+
*cache

app/main.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
from fastapi.templating import Jinja2Templates
1111
from typing import Any
1212

13-
MODEL_PATH = Path(os.getenv("MODEL_PATH", "/models/carworth_hgbr_v1.joblib"))
14-
META_PATH = Path(
15-
os.getenv("MODEL_META", str(MODEL_PATH).replace(".joblib", ".meta.json"))
16-
)
13+
PROJECT_ROOT = Path(__file__).resolve().parents[1]
14+
15+
DEFAULT_MODEL = PROJECT_ROOT / "models" / "carworth_hgbr_v1.joblib"
16+
MODEL_PATH = Path(os.getenv("MODEL_PATH", str(DEFAULT_MODEL))).resolve()
17+
18+
DEFAULT_META = Path(str(MODEL_PATH).replace(".joblib", ".meta.json"))
19+
META_PATH = Path(os.getenv("MODEL_META", str(DEFAULT_META))).resolve()
1720

1821

1922
class CarInput(BaseModel):

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
testpaths = tests
3+
pythonpath = .

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ pydantic
1515
uvicorn[standard]
1616
Jinja2
1717
python-multipart
18-
httpx>=0.27
18+
httpx>=0.27
19+
python-multipart

tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import sys, os
2+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

tests/test_api.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from fastapi.testclient import TestClient
22
from app.main import app
33

4-
54
def test_health():
6-
c = TestClient(app)
7-
r = c.get("/health")
8-
assert r.status_code == 200
9-
assert r.json()["ok"] is True
5+
with TestClient(app) as c:
6+
r = c.get("/health")
7+
assert r.status_code == 200
8+
assert r.json()["ok"] is True

0 commit comments

Comments
 (0)