Repository navigation
fix(test): restore registry module after reinforce++ registry fixture - #250
Closed
xcosmosbox wants to merge 1 commit into
Closed
xcosmosbox wants to merge 1 commit into
xcosmosbox wants to merge 1 commit into
Conversation
The registry_module fixture in test_registry_reinforce_plus_plus.py popped relax.core.registry from sys.modules during teardown without restoring it. Any later test in the same pytest process that re-imports the module gets a fresh instance, so process_role (old instance) returns a ROLES_COLOCATE that fails is comparison against the re-imported one. This broke test_registry_sft.py (and test_registry_rloo.py once it lands) in full-suite runs. Save and restore the original module entry in teardown.
11 of 16 tasks
Contributor
Author
|
已被事实性修复,所以关闭本 PR |
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
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.
该问题由 #202 新增的
tests/core/test_registry_reinforce_plus_plus.py引入。其
registry_modulefixture 在 teardown 中执行sys.modules.pop("relax.core.registry"),但没有恢复原始模块。在同一个 pytest 进程中,任何后续测试再次触发import relax.core.registry时都会重新导入并得到一个新的模块实例:from relax.core.registry import process_role绑定的是旧实例;from relax.core.registry import ROLES_COLOCATE拿到的是新实例;process_role返回的ROLES_COLOCATE与新实例做is比较必然失败。因此
test_registry_sft.py的两个测试在全量测试运行时受执行顺序影响而失败(单独运行不受影响);该问题在纯 main 上同样可复现,与任何 PR 的改动无关。What
修复
tests/core/test_registry_reinforce_plus_plus.py中registry_modulefixture 的测试隔离问题。该 fixture 在 teardown 中弹出sys.modules["relax.core.registry"]后未恢复原始模块,导致同一 pytest 进程内的后续测试重新导入得到新的模块实例,最终使依赖is比较的断言失败。Why
test_registry_sft.py的两个测试(以及 【NO.28】实现 RLOO advantage estimator #205 将新增的test_registry_rloo.py)会因模块实例不一致而失败;单独运行或分文件运行则不受影响。How
在 fixture 中先保存
sys.modules中原有的relax.core.registry引用,teardown 弹出测试期模块后,若存在原始引用则恢复之。这样后续测试始终拿到同一个模块实例,process_role返回的ROLES_COLOCATE与测试内导入的枚举保持同一对象。Testing
pytest tests/core/:全部通过(此前 3 个失败消除)pytest tests/core/test_registry_reinforce_plus_plus.py tests/core/test_registry_sft.py:此前失败的组合全部通过pre-commit run --all-files:全部通过pre-commit run --all-filespassesTests pass (
pytest tests/)New tests added (if applicable)
Documentation updated (if applicable)
Type of Change