test-fixing
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTest Fixing
测试修复
Systematically identify and fix all failing tests using smart grouping strategies.
通过智能分组策略系统地识别并修复所有失败的测试。
When to Use
适用场景
- Explicitly asks to fix tests ("fix these tests", "make tests pass")
- Reports test failures ("tests are failing", "test suite is broken")
- Completes implementation and wants tests passing
- Mentions CI/CD failures due to tests
- 明确要求修复测试(“修复这些测试”、“确保测试通过”)
- 报告测试失败(“测试失败了”、“测试套件损坏”)
- 完成实现后希望测试通过
- 提及因测试导致的CI/CD失败
Systematic Approach
系统方法
1. Initial Test Run
1. 初始测试运行
Run to identify all failing tests.
make testAnalyze output for:
- Total number of failures
- Error types and patterns
- Affected modules/files
运行以识别所有失败的测试。
make test分析输出内容,关注:
- 失败总数
- 错误类型和模式
- 受影响的模块/文件
2. Smart Error Grouping
2. 智能错误分组
Group similar failures by:
- Error type: ImportError, AttributeError, AssertionError, etc.
- Module/file: Same file causing multiple test failure
- Root cause: Missing dependencies, API changes, refactoring impacts
Prioritize groups by:
- Number of affected tests (highest impact first)
- Dependency order (fix infrastructure before functionality)
按以下维度对相似失败进行分组:
- 错误类型:ImportError、AttributeError、AssertionError等
- 模块/文件:同一文件导致多个测试失败
- 根本原因:依赖缺失、API变更、重构影响
按以下优先级处理分组:
- 受影响测试数量(影响范围最大的优先)
- 依赖顺序(先修复基础设施问题,再处理功能问题)
3. Systematic Fixing Process
3. 系统修复流程
For each group (starting with highest impact):
-
Identify root cause
- Read relevant code
- Check recent changes with
git diff - Understand the error pattern
-
Implement fix
- Use Edit tool for code changes
- Follow project conventions (see CLAUDE.md)
- Make minimal, focused changes
-
Verify fix
- Run subset of tests for this group
- Use pytest markers or file patterns:
bash
uv run pytest tests/path/to/test_file.py -v uv run pytest -k "pattern" -v - Ensure group passes before moving on
-
Move to next group
针对每个分组(从影响最大的开始):
-
识别根本原因
- 阅读相关代码
- 使用检查最近的变更
git diff - 理解错误模式
-
实施修复
- 使用编辑工具进行代码变更
- 遵循项目约定(参考CLAUDE.md)
- 进行最小化、针对性的变更
-
验证修复
- 运行该分组的测试子集
- 使用pytest标记或文件模式:
bash
uv run pytest tests/path/to/test_file.py -v uv run pytest -k "pattern" -v - 确保当前分组通过后再进行下一组
-
处理下一个分组
4. Fix Order Strategy
4. 修复顺序策略
Infrastructure first:
- Import errors
- Missing dependencies
- Configuration issues
Then API changes:
- Function signature changes
- Module reorganization
- Renamed variables/functions
Finally, logic issues:
- Assertion failures
- Business logic bugs
- Edge case handling
先处理基础设施问题:
- 导入错误
- 依赖缺失
- 配置问题
再处理API变更:
- 函数签名变更
- 模块重组
- 变量/函数重命名
最后处理逻辑问题:
- 断言失败
- 业务逻辑漏洞
- 边缘情况处理
5. Final Verification
5. 最终验证
After all groups fixed:
- Run complete test suite:
make test - Verify no regressions
- Check test coverage remains intact
修复所有分组后:
- 运行完整测试套件:
make test - 验证无回归问题
- 确保测试覆盖率保持不变
Best Practices
最佳实践
- Fix one group at a time
- Run focused tests after each fix
- Use to understand recent changes
git diff - Look for patterns in failures
- Don't move to next group until current passes
- Keep changes minimal and focused
- 一次修复一个分组
- 每次修复后运行针对性测试
- 使用了解最近的变更
git diff - 寻找失败中的模式
- 当前分组未通过前不要进行下一组
- 保持变更最小且有针对性
Example Workflow
示例工作流
User: "The tests are failing after my refactor"
- Run → 15 failures identified
make test - Group errors:
- 8 ImportErrors (module renamed)
- 5 AttributeErrors (function signature changed)
- 2 AssertionErrors (logic bugs)
- Fix ImportErrors first → Run subset → Verify
- Fix AttributeErrors → Run subset → Verify
- Fix AssertionErrors → Run subset → Verify
- Run full suite → All pass ✓
用户:“我重构后测试失败了”
- 运行→ 识别出15个失败
make test - 分组错误:
- 8个ImportErrors(模块重命名)
- 5个AttributeErrors(函数签名变更)
- 2个AssertionErrors(逻辑漏洞)
- 先修复ImportErrors → 运行子集测试 → 验证通过
- 修复AttributeErrors → 运行子集测试 → 验证通过
- 修复AssertionErrors → 运行子集测试 → 验证通过
- 运行完整套件 → 全部通过 ✓