Skip to content

Commit 05100a3

Browse files
fix: guard web tests with importorskip(fastapi) for CI
Web tests import fastapi.testclient at module level which fails in CI where fastapi is not installed (optional dep). Add importorskip guard. Also exclude cli/_web.py from pyright (imports uvicorn, optional dep). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dd2cc4f commit 05100a3

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

packages/studyctl/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ packages = ["src/studyctl"]
5050
[tool.pyright]
5151
pythonVersion = "3.12"
5252
typeCheckingMode = "basic"
53-
exclude = ["src/studyctl/tui", "src/studyctl/content", "src/studyctl/cli/_content.py", "src/studyctl/web", "src/studyctl/mcp"] # optional deps not in CI
53+
exclude = ["src/studyctl/tui", "src/studyctl/content", "src/studyctl/cli/_content.py", "src/studyctl/cli/_web.py", "src/studyctl/web", "src/studyctl/mcp"] # optional deps not in CI

packages/studyctl/tests/test_web_app.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
from __future__ import annotations
44

55
from typing import TYPE_CHECKING
6-
from unittest.mock import patch
76

8-
import pytest
9-
from fastapi.testclient import TestClient
7+
pytest = __import__("pytest")
8+
pytest.importorskip("fastapi")
109

11-
from studyctl.web.app import create_app
10+
from unittest.mock import patch # noqa: E402
11+
12+
from fastapi.testclient import TestClient # noqa: E402
13+
14+
from studyctl.web.app import create_app # noqa: E402
1215

1316
if TYPE_CHECKING:
1417
from pathlib import Path

packages/studyctl/tests/test_web_artefacts.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
from __future__ import annotations
44

55
from typing import TYPE_CHECKING
6-
from unittest.mock import patch
76

8-
import pytest
9-
from fastapi.testclient import TestClient
7+
pytest = __import__("pytest")
8+
pytest.importorskip("fastapi")
109

11-
from studyctl.web.app import create_app
10+
from unittest.mock import patch # noqa: E402
11+
12+
from fastapi.testclient import TestClient # noqa: E402
13+
14+
from studyctl.web.app import create_app # noqa: E402
1215

1316
if TYPE_CHECKING:
1417
from pathlib import Path

0 commit comments

Comments
 (0)