Skip to content

Commit 002f993

Browse files
committed
Mock Modal module at import time in test conftest
Patch modal decorators to be pass-through functions so github_webhook handler can be tested without Modal runtime.
1 parent 68e6fc0 commit 002f993

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
1+
import sys
2+
from unittest.mock import MagicMock
3+
14
import pytest
25

36

7+
@pytest.fixture(autouse=True, scope="session")
8+
def _mock_modal_decorators():
9+
mock_modal = MagicMock()
10+
mock_modal.Image.from_registry.return_value = MagicMock()
11+
mock_modal.App.return_value = MagicMock()
12+
mock_modal.Secret.from_name.return_value = MagicMock()
13+
mock_modal.Queue.from_name.return_value = MagicMock()
14+
mock_modal.Sandbox.list.return_value = []
15+
mock_modal.fastapi_endpoint = lambda **kwargs: lambda f: f
16+
mock_app = MagicMock()
17+
mock_app.function = lambda **kwargs: lambda f: f
18+
mock_app.app_id = "test-app-id"
19+
mock_modal.App.return_value = mock_app
20+
21+
sys.modules["modal"] = mock_modal
22+
23+
yield
24+
25+
sys.modules.pop("modal", None)
26+
27+
428
@pytest.fixture(autouse=True)
529
def set_env(monkeypatch):
630
monkeypatch.setenv("WEBHOOK_SECRET", "test-secret")

0 commit comments

Comments
 (0)