test-fix

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

test-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

操作步骤

  1. Read the failure output carefully — identify the root cause (assertion error, import error, missing mock, timeout, etc.).
  2. Locate the source code the test exercises — the fix may be in the source, not the test itself.
  3. Follow existing patterns: Look at passing tests in the same file for mock setup and assertion style.
  4. Preserve test intent: Never weaken assertions to make tests pass. Fix the underlying issue.
  5. Run the fix: Execute
    pytest tests/<file> -v
    to confirm the fix works.
  1. 仔细阅读失败输出——确定根本原因(断言错误、导入错误、缺失模拟、超时等)。
  2. 定位测试涉及的源代码——修复可能需要修改源代码而非测试本身。
  3. 遵循现有模式:查看同一文件中通过的测试,参考其模拟设置和断言风格。
  4. 保留测试意图:绝不要通过弱化断言来让测试通过。修复底层问题。
  5. 运行修复后的测试:执行
    pytest tests/<file> -v
    确认修复有效。

Project Testing Conventions

项目测试规范

  • Framework: pytest with
    pytest-asyncio
    and
    pytest-httpx
  • HTTP mocking: Use
    HTTPXMock
    from
    pytest-httpx
    for transport tests
  • Fixtures: Common fixtures in
    tests/conftest.py
    mock_auth_token
    ,
    mock_context_uuid
    ,
    mock_frontend_uuid
    ,
    mock_backend_uuid
  • Test naming:
    test_<what>_<behavior>
    (e.g.,
    test_http_transport_auth_error
    )
  • Structure: Arrange-Act-Assert pattern
  • No docstrings needed in test files (per ruff config)
  • 框架:使用pytest,搭配
    pytest-asyncio
    pytest-httpx
  • HTTP模拟:在传输测试中使用
    pytest-httpx
    提供的
    HTTPXMock
  • 夹具:通用夹具位于
    tests/conftest.py
    中——
    mock_auth_token
    ,
    mock_context_uuid
    ,
    mock_frontend_uuid
    ,
    mock_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
undefined

AuthenticationError 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
undefined
with pytest.raises(AuthenticationError) as exc_info: transport.request("GET", "/api/test") assert exc_info.value.status_code == 401
undefined

Common Issues

常见问题

SymptomLikely CauseFix
ImportError
Module restructuredUpdate import path
AttributeError
Model field renamedCheck
domain/models.py
HTTPXMock
not matching
URL or method mismatchVerify mock URL matches request
TransportError
vs
RuntimeError
Exception type changedUse
pplx_sdk.core.exceptions
types
症状可能原因修复方案
ImportError
模块结构调整更新导入路径
AttributeError
模型字段重命名检查
domain/models.py
HTTPXMock
不匹配
URL或方法不匹配验证模拟URL与请求URL一致
TransportError
RuntimeError
混淆
异常类型变更使用
pplx_sdk.core.exceptions
中的类型