test-fix
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesetest-fix
测试修复
Diagnose and fix failing tests following pplx-sdk testing conventions.
按照pplx-sdk的测试规范诊断并修复失败的测试用例。
When to use
适用场景
Use this skill when pytest tests fail and you need to identify the root cause and apply the correct fix.
当pytest测试用例失败,你需要定位根本原因并应用正确修复方案时,可使用此技能。
Instructions
操作步骤
- Read the failure output carefully — identify the root cause (assertion error, import error, missing mock, timeout, etc.).
- Locate the source code the test exercises — the fix may be in the source, not the test itself.
- Follow existing patterns: Look at passing tests in the same file for mock setup and assertion style.
- Preserve test intent: Never weaken assertions to make tests pass. Fix the underlying issue.
- Run the fix: Execute to confirm the fix works.
pytest tests/<file> -v
- 仔细阅读失败输出——确定根本原因(断言错误、导入错误、缺失模拟、超时等)。
- 定位测试涉及的源代码——修复可能需要修改源代码而非测试本身。
- 遵循现有模式:查看同一文件中通过的测试,参考其模拟设置和断言风格。
- 保留测试意图:绝不要通过弱化断言来让测试通过。修复底层问题。
- 运行修复后的测试:执行确认修复有效。
pytest tests/<file> -v
Project Testing Conventions
项目测试规范
- Framework: pytest with and
pytest-asynciopytest-httpx - HTTP mocking: Use from
HTTPXMockfor transport testspytest-httpx - Fixtures: Common fixtures in —
tests/conftest.py,mock_auth_token,mock_context_uuid,mock_frontend_uuidmock_backend_uuid - Test naming: (e.g.,
test_<what>_<behavior>)test_http_transport_auth_error - Structure: Arrange-Act-Assert pattern
- No docstrings needed in test files (per ruff config)
- 框架:使用pytest,搭配和
pytest-asynciopytest-httpx - HTTP模拟:在传输测试中使用提供的
pytest-httpxHTTPXMock - 夹具:通用夹具位于中——
tests/conftest.py,mock_auth_token,mock_context_uuid,mock_frontend_uuidmock_backend_uuid - 测试命名:采用格式(例如:
test_<测试对象>_<行为>)test_http_transport_auth_error - 结构:遵循Arrange-Act-Assert模式
- 测试文件无需文档字符串(根据ruff配置)
Exception Testing
异常测试
Verify the exception hierarchy when testing error cases:
python
undefined测试错误场景时,验证异常层级:
python
undefinedAuthenticationError is a TransportError which is a PerplexitySDKError
AuthenticationError 是 TransportError 的子类,而 TransportError 是 PerplexitySDKError 的子类
with pytest.raises(AuthenticationError) as exc_info:
transport.request("GET", "/api/test")
assert exc_info.value.status_code == 401
undefinedwith pytest.raises(AuthenticationError) as exc_info:
transport.request("GET", "/api/test")
assert exc_info.value.status_code == 401
undefinedCommon Issues
常见问题
| Symptom | Likely Cause | Fix |
|---|---|---|
| Module restructured | Update import path |
| Model field renamed | Check |
| URL or method mismatch | Verify mock URL matches request |
| Exception type changed | Use |
| 症状 | 可能原因 | 修复方案 |
|---|---|---|
| 模块结构调整 | 更新导入路径 |
| 模型字段重命名 | 检查 |
| URL或方法不匹配 | 验证模拟URL与请求URL一致 |
| 异常类型变更 | 使用 |