-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: unit tests #2760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix: unit tests #2760
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你好 - 我已审阅了你的更改 - 以下是一些反馈意见:
- 插件管理器测试仍然执行真实的 GitHub 安装——考虑模拟克隆/下载步骤或使用本地测试夹具以避免网络不稳定。
- 在你的仪表板测试中,你混合使用了 pytest.fixture 和 pytest_asyncio.fixture 来处理异步夹具——请统一它们(及其作用域),使所有异步夹具都使用 pytest_asyncio 以提高清晰度。
- 在 test_main 中,你调用了 mock.patch 而没有导入或别名 mock;请添加正确的导入(例如,from unittest import mock)以防止 NameError。
供 AI 代理的提示
请处理此代码审查中的评论:
## 总体评论
- 插件管理器测试仍然执行真实的 GitHub 安装——考虑模拟克隆/下载步骤或使用本地测试夹具以避免网络不稳定。
- 在你的仪表板测试中,你混合使用了 pytest.fixture 和 pytest_asyncio.fixture 来处理异步夹具——请统一它们(及其作用域),使所有异步夹具都使用 pytest_asyncio 以提高清晰度。
- 在 test_main 中,你调用了 mock.patch 而没有导入或别名 mock;请添加正确的导入(例如,from unittest import mock)以防止 NameError。
## 单独评论
### 评论 1
<location> `tests/test_plugin_manager.py:100` </location>
<code_context>
+
+
+@pytest.mark.asyncio
+async def test_update_plugin(plugin_manager_pm: PluginManager):
+ """Tests updating an existing plugin in an isolated environment."""
+ # First, install the plugin
+ test_repo = "https://github.com/Soulter/astrbot_plugin_essential"
+ await plugin_manager_pm.install_plugin(test_repo)
- # update
+ # Then, update it
await plugin_manager_pm.update_plugin("astrbot_plugin_essential")
+
</code_context>
<issue_to_address>
测试未对插件更新的任何结果进行断言。
添加断言以确认插件已更新,例如验证文件更改、版本或注册表状态。
</issue_to_address>
### 评论 2
<location> `tests/test_dashboard.py:84` </location>
<code_context>
@pytest.mark.asyncio
-async def test_plugins(app: Quart, header: dict):
+async def test_plugins(app: Quart, authenticated_header: dict):
test_client = app.test_client()
# 已经安装的插件
- response = await test_client.get("/api/plugin/get", headers=header)
+ response = await test_client.get("/api/plugin/get", headers=authenticated_header)
assert response.status_code == 200
data = await response.get_json()
assert data["status"] == "ok"
# 插件市场
</code_context>
<issue_to_address>
缺少使用无效 URL 安装插件的负面测试。
添加一个测试,尝试使用无效或格式错误的 URL 安装插件,并验证 API 返回错误响应。
</issue_to_address>帮助我更有用!请点击每个评论上的 👍 或 👎,我将使用反馈来改进你的评论。
Original comment in English
Hey there - I've reviewed your changes - here's some feedback:
- The plugin manager tests still perform real GitHub installs—consider mocking the clone/download steps or using a local test fixture to avoid network flakiness.
- You’ve mixed pytest.fixture and pytest_asyncio.fixture for async fixtures in your dashboard tests—unify them (and their scopes) so all async fixtures use pytest_asyncio for clarity.
- In test_main you call mock.patch without importing or aliasing mock; add the proper import (e.g., from unittest import mock) to prevent NameError.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The plugin manager tests still perform real GitHub installs—consider mocking the clone/download steps or using a local test fixture to avoid network flakiness.
- You’ve mixed pytest.fixture and pytest_asyncio.fixture for async fixtures in your dashboard tests—unify them (and their scopes) so all async fixtures use pytest_asyncio for clarity.
- In test_main you call mock.patch without importing or aliasing mock; add the proper import (e.g., from unittest import mock) to prevent NameError.
## Individual Comments
### Comment 1
<location> `tests/test_plugin_manager.py:100` </location>
<code_context>
+
+
+@pytest.mark.asyncio
+async def test_update_plugin(plugin_manager_pm: PluginManager):
+ """Tests updating an existing plugin in an isolated environment."""
+ # First, install the plugin
+ test_repo = "https://github.com/Soulter/astrbot_plugin_essential"
+ await plugin_manager_pm.install_plugin(test_repo)
- # update
+ # Then, update it
await plugin_manager_pm.update_plugin("astrbot_plugin_essential")
+
</code_context>
<issue_to_address>
Test does not assert any outcome for plugin update.
Add assertions to confirm the plugin was updated, such as verifying changes to files, version, or registry state.
</issue_to_address>
### Comment 2
<location> `tests/test_dashboard.py:84` </location>
<code_context>
@pytest.mark.asyncio
-async def test_plugins(app: Quart, header: dict):
+async def test_plugins(app: Quart, authenticated_header: dict):
test_client = app.test_client()
# 已经安装的插件
- response = await test_client.get("/api/plugin/get", headers=header)
+ response = await test_client.get("/api/plugin/get", headers=authenticated_header)
assert response.status_code == 200
data = await response.get_json()
assert data["status"] == "ok"
# 插件市场
</code_context>
<issue_to_address>
Missing negative test for plugin installation with invalid URL.
Add a test that attempts to install a plugin using an invalid or malformed URL, and verify that the API returns an error response.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Soulter
approved these changes
Sep 27, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / 动机
似乎单元测试一直是坏的,至少需要开个头把他修复起来
Modifications / 改动点
修改了tests文件夹下的pytest脚本,未修改主程序
Verification Steps / 验证步骤
使用pytest框架运行测试即可
Screenshots or Test Results / 运行截图或测试结果
除pipeline部分外已修复
Compatibility & Breaking Changes / 兼容性与破坏性变更
重构并拆分了部分测试方法,但原来测试本就是不可用状态
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.Sourcery 总结
全面改进测试套件,通过重构和隔离 PluginManager、dashboard 和主测试来修复 pytest 故障,采用异步 fixture 并模拟外部依赖项,以实现可靠执行。
增强功能:
Original summary in English
Summary by Sourcery
Overhaul the test suite by refactoring and isolating PluginManager, dashboard, and main tests to fix pytest failures, adopt async fixtures, and mock external dependencies for reliable execution.
Enhancements: