test: fix test isolation and compatibility issues#5404
test: fix test isolation and compatibility issues#5404whatevertogo wants to merge 6 commits intoAstrBotDevs:masterfrom
Conversation
- Use local mock plugin instead of real network requests - Clear sys.modules cache for entire data module tree - Clear star_map and star_registry in teardown - Use pytest_asyncio.fixture for async fixture support Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- test_main.py: fix version comparison and path assertions for Windows - test_smoke.py: add missing apscheduler.triggers mock modules - test_tool_loop_agent_runner.py: update assertion for new interrupt behavior - test_api_key_open_api.py: use unique session IDs to avoid test conflicts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello @whatevertogo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request primarily focuses on enhancing the robustness and reliability of the test suite. It addresses several issues related to test isolation, ensuring that individual tests do not interfere with each other's state. Additionally, it improves cross-platform compatibility, particularly for Windows, and updates tests to align with recent changes in system behavior, such as how interrupted processes are reported. The overall goal is to create a more stable and predictable testing environment. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Hey - 我发现了 1 个问题
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/test_main.py" line_range="19-27" />
<code_context>
self.major = major
self.minor = minor
+ def __eq__(self, other):
+ if isinstance(other, tuple):
+ return (self.major, self.minor) == other[:2]
+ return (self.major, self.minor) == (other.major, other.minor)
+
+ def __ge__(self, other):
+ if isinstance(other, tuple):
+ return (self.major, self.minor) >= other[:2]
+ return (self.major, self.minor) >= (other.major, other.minor)
+
</code_context>
<issue_to_address>
**suggestion (testing):** 为 _version_info 与元组和实例之间的比较添加单元级检查
这些 `__eq__` 和 `__ge__` 方法目前只通过 `test_check_env` 间接覆盖。请添加一个有针对性的测试(例如 `test_version_info_comparisons`),直接验证它们与元组和 `_version_info` 实例之间的比较行为,包括:
- `_version_info(3, 10) >= (3, 10)` 且 `== (3, 10)`
- `_version_info(3, 9) >= (3, 10)` 为 `False`
- `_version_info(3, 10) >= _version_info(3, 10)` 以及类似的实例对实例比较。
这样即使以后 `check_env` 发生变更,也能稳固这些比较语义。
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据这些反馈改进之后的评审。
Original comment in English
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/test_main.py" line_range="19-27" />
<code_context>
self.major = major
self.minor = minor
+ def __eq__(self, other):
+ if isinstance(other, tuple):
+ return (self.major, self.minor) == other[:2]
+ return (self.major, self.minor) == (other.major, other.minor)
+
+ def __ge__(self, other):
+ if isinstance(other, tuple):
+ return (self.major, self.minor) >= other[:2]
+ return (self.major, self.minor) >= (other.major, other.minor)
+
</code_context>
<issue_to_address>
**suggestion (testing):** Add unit-level checks for _version_info comparisons against tuples and instances
These `__eq__` and `__ge__` methods are currently only covered indirectly via `test_check_env`. Please add a focused test (e.g. `test_version_info_comparisons`) that directly exercises comparisons against both tuples and `_version_info` instances, including:
- `_version_info(3, 10) >= (3, 10)` and `== (3, 10)`
- `_version_info(3, 9) >= (3, 10)` is `False`
- `_version_info(3, 10) >= _version_info(3, 10)` and similar instance-to-instance comparisons.
This will anchor the comparison semantics even if `check_env` changes later.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces a series of valuable improvements to the test suite, focusing on enhancing test isolation, reliability, and cross-platform compatibility. The changes are well-executed and address several important testing concerns.
Key improvements include:
- Test Isolation: The use of unique session and creator IDs in
test_api_key_open_api.pyeffectively prevents test conflicts. The major refactoring oftest_plugin_manager.pyis particularly noteworthy, introducing a fully isolated environment for plugin tests by mocking network-dependent operations and ensuring proper cleanup of modules and global registries. - Cross-Platform Compatibility: The updates in
test_main.pyto useos.path.joinfor path assertions make the tests more robust and able to run on different operating systems like Windows. - Test Reliability: Mocking missing
apscheduler.triggersintest_smoke.pyand updating assertions intest_tool_loop_agent_runner.pyto match new application behavior contribute to a more stable and reliable test suite.
Overall, these changes significantly improve the quality of the tests. The code is clean, and the approach to improving test isolation is excellent. I have no further comments. Great work!
Summary
Test plan
🤖 Generated with Claude Code
Summary by Sourcery
在插件管理器、API Key、环境、冒烟测试和工具运行器等测试中,提高测试隔离性、可靠性以及跨平台兼容性。
Bug 修复:
Original summary in English
Summary by Sourcery
Improve test isolation, reliability, and cross-platform compatibility across plugin manager, API key, environment, smoke, and tool runner tests.
Bug Fixes: