test(ci): 修复10个ruff错误 + Unit Tests dedup收集失败 (#839 #881) #896

Merged
xiaoxia merged 1 commits from fix/ci-ruff-unit-tests-red into develop 2026-07-25 17:38:17 +08:00
Owner

任务1:修复Code Quality的10个ruff错误(#839)

修改内容

文件 问题 修复
tests/unit/test_jwt_handler.py 4个B017 pytest.raises(Exception) 改为具体异常:ExpiredSignatureError(过期) / InvalidTokenError(无效/空/错密钥)
tests/unit/test_domain_remaining_small_modules.py 2个B017 pytest.raises(Exception) 改为 FrozenInstanceError(frozen dataclass)
tests/unit/test_filter_presets.py 1个B017 pytest.raises(Exception) 改为 FrozenInstanceError
tests/unit/test_transition_presets.py 1个B017 + 1个F541 B017→FrozenInstanceError,F541去掉f前缀
tests/unit/test_email_service_smtp.py 1个E721 type(a) == type(b) 改为 type(a) is type(b)

结果:ruff check全通过

任务2:修复Unit Tests收集失败(#881)

问题

test_dedup_pure.py 导入 video_processing.dedup 时,模块顶层 from worker_app.db import SessionLocal 触发 ensure_database_exists()pg_database 表,sqlite环境直接崩溃,导致6275个测试收集失败。

修复

test_dedup_pure.py 已有 sys.modules["cv2"] mock的基础上,增加 sys.modules["worker_app.db"] mock。纯算法测试不需要数据库,模块级mock避免导入时触发初始化。

结果:6275个测试全部收集成功

范围

  • 只改测试文件,不动业务逻辑
  • 共6个文件,+17 -10行

关联工单

  • #839 Code Quality 10个ruff错误
  • #881 Unit Tests收集失败
## 任务1:修复Code Quality的10个ruff错误(#839) ### 修改内容 | 文件 | 问题 | 修复 | |------|------|------| | `tests/unit/test_jwt_handler.py` | 4个B017 `pytest.raises(Exception)` | 改为具体异常:`ExpiredSignatureError`(过期) / `InvalidTokenError`(无效/空/错密钥) | | `tests/unit/test_domain_remaining_small_modules.py` | 2个B017 `pytest.raises(Exception)` | 改为 `FrozenInstanceError`(frozen dataclass) | | `tests/unit/test_filter_presets.py` | 1个B017 `pytest.raises(Exception)` | 改为 `FrozenInstanceError` | | `tests/unit/test_transition_presets.py` | 1个B017 + 1个F541 | B017→`FrozenInstanceError`,F541去掉f前缀 | | `tests/unit/test_email_service_smtp.py` | 1个E721 `type(a) == type(b)` | 改为 `type(a) is type(b)` | **结果**:ruff check全通过 ✅ ## 任务2:修复Unit Tests收集失败(#881) ### 问题 `test_dedup_pure.py` 导入 `video_processing.dedup` 时,模块顶层 `from worker_app.db import SessionLocal` 触发 `ensure_database_exists()` 查 `pg_database` 表,sqlite环境直接崩溃,导致6275个测试收集失败。 ### 修复 在 `test_dedup_pure.py` 已有 `sys.modules["cv2"]` mock的基础上,增加 `sys.modules["worker_app.db"]` mock。纯算法测试不需要数据库,模块级mock避免导入时触发初始化。 **结果**:6275个测试全部收集成功 ✅ ## 范围 - 只改测试文件,不动业务逻辑 - 共6个文件,+17 -10行 ## 关联工单 - #839 Code Quality 10个ruff错误 - #881 Unit Tests收集失败
xiaoxia force-pushed fix/ci-ruff-unit-tests-red from 16a97e0f39 to 0498f4a7e5 2026-07-25 17:26:13 +08:00 Compare
xiaoxia added 1 commit 2026-07-25 17:32:50 +08:00
test(ci): 修复10个ruff错误 + Unit Tests dedup收集失败 (#839 #881)
AI Code Review / AI Code Review (pull_request) Failing after 0s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 15s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 46s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m40s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m41s
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 1m6s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 28s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 1m51s
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 3m37s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m32s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 4m55s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m18s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 11s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Failing after 11s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m51s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 48m44s
f4b263bac8
xiaoxia force-pushed fix/ci-ruff-unit-tests-red from 0498f4a7e5 to f4b263bac8 2026-07-25 17:32:50 +08:00 Compare
xiaoxia merged commit 2972f19954 into develop 2026-07-25 17:38:17 +08:00
xiaoxia deleted branch fix/ci-ruff-unit-tests-red 2026-07-25 17:38:17 +08:00

🗑️ 预览环境已清理

PR #896 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #896 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.