Skip to content

Commit

Permalink
test: 修复没有正确 mock 文件导致 Actions 运行测试时会输出作业摘要的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
he0119 committed Dec 11, 2024
1 parent a02ad0b commit 7066f28
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/plugins/github/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ class Config(BaseModel, extra="ignore"):
input_config: PublishConfig
github_repository: str
github_run_id: str
github_step_summary: Path
12 changes: 5 additions & 7 deletions src/plugins/github/plugins/publish/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from src.plugins.github.models.issue import IssueHandler
from src.plugins.github.utils import extract_issue_info_from_issue
from src.providers.docker_test import DockerPluginTest, Metadata
from src.providers.utils import get_latest_version, load_json_from_file
from src.providers.utils import (
add_step_summary,
get_latest_version,
load_json_from_file,
)
from src.providers.validation import PublishType, ValidationDict, validate_info

from .constants import (
Expand Down Expand Up @@ -41,12 +45,6 @@ def strip_ansi(text: str | None) -> str:
return ansi_escape.sub("", text)


def add_step_summary(summary: str):
"""添加作业摘要"""
with plugin_config.github_step_summary.open("a", encoding="utf-8") as f:
f.write(summary + "\n")


async def validate_plugin_info_from_issue(
handler: IssueHandler,
skip_test: bool | None = None,
Expand Down
9 changes: 4 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def pytest_configure(config: pytest.Config) -> None:
"github_run_id": "123456",
"github_event_path": "event_path",
"github_apps": [],
"github_step_summary": "step_summary",
}


Expand All @@ -44,7 +43,9 @@ def load_plugin(nonebug_init: None) -> set["Plugin"]:


@pytest.fixture
async def app(app: App, tmp_path: Path, mocker: MockerFixture):
async def app(
app: App, tmp_path: Path, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch
):
from src.plugins.github import plugin_config
from src.providers.utils import dump_json5

Expand Down Expand Up @@ -95,9 +96,7 @@ async def app(app: App, tmp_path: Path, mocker: MockerFixture):
mocker.patch.object(plugin_config.input_config, "adapter_path", adapter_path)
mocker.patch.object(plugin_config.input_config, "bot_path", bot_path)
mocker.patch.object(plugin_config.input_config, "plugin_path", plugin_path)
mocker.patch.object(
plugin_config, "github_step_summary", tmp_path / "step_summary.txt"
)
monkeypatch.setenv("GITHUB_STEP_SUMMARY", str(tmp_path / "step_summary.md"))

yield app

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

from githubkit.rest import Issue
from inline_snapshot import snapshot
from nonebug import App
Expand Down Expand Up @@ -48,9 +50,8 @@ async def test_validate_info_from_issue_bot(


async def test_validate_info_from_issue_plugin(
app: App, mocker: MockerFixture, mocked_api: MockRouter
app: App, mocker: MockerFixture, mocked_api: MockRouter, tmp_path: Path
):
from src.plugins.github import plugin_config
from src.plugins.github.models import RepoInfo
from src.plugins.github.models.issue import IssueHandler
from src.plugins.github.plugins.publish.validation import (
Expand Down Expand Up @@ -100,7 +101,8 @@ async def test_validate_info_from_issue_plugin(

assert result.valid
assert mocked_api["homepage"].called
assert plugin_config.github_step_summary.read_text(encoding="utf-8") == snapshot(
step_summary_file = tmp_path / "step_summary.md"
assert step_summary_file.read_text(encoding="utf-8") == snapshot(
"""\
# 📃 插件 project_link (1.0.0)
Expand Down

0 comments on commit 7066f28

Please sign in to comment.