fix(tests): TETRA-2134 — import ModuleType in 3 test files (clear ruff F821) #165

Merged
tant merged 1 commit from fix/TETRA-2134-f821-moduletype into main 2026-06-17 03:09:37 +07:00
Owner

Summary

Investigation của TETRA-2134: 3 lỗi F821 undefined-name trong ruff baseline đều là cùng 1 nguyên nhân — -> ModuleType dùng làm return annotation nhưng ModuleType không được import.

Kết luận điều tra: KHÔNG phải bug runtime — cả 3 file có from __future__ import annotations (Python 3.10) nên annotation bị hoãn thành string, không bao giờ eval khi import (đã xác nhận import sạch, exit 0). Nhưng vẫn là F821 thật: tham chiếu tên chưa định nghĩa, phá typing.get_type_hints(), ruff bắt đúng.

Fix: thêm from types import ModuleType (đúng thứ tự isort, trước from unittest.mock) vào:

  • test_asset_categories.py
  • test_asset_movement_custom_fields.py
  • test_setup_verification.py

Test Plan

  • ruff check --select F821 . → All checks passed (3 → 0)
  • ModuleType không bị F401 (được dùng trong annotation)
  • 3 test file chạy từng file riêng: OK (5 + 6 + 14 test; 2 skipped)

Ghi chú (baseline triage — đề xuất tách ticket riêng)

Baseline ruff toàn repo hiện ~585 lỗi. Phân loại để đưa về 0 + bật full ruff check trong CI:

  • RUF001/2/3 (~247): unicode tiếng Việt trong string/comment → nên ignore (repo VN, không phải lỗi).
  • I001 (~157 import-sort) + RUF100 (~66 noqa thừa): ruff check --fix autofix an toàn.
  • Còn lại (F401 unused như sys, lặt vặt): dọn thủ công từng nhóm.
    → Đề xuất follow-up ticket: set ignore-list RUF001/2/3, autofix I001/RUF100, dọn phần còn lại, rồi đổi CI gate từ --select S110 sang full ruff check.

🤖 Generated with Claude Code

## Summary Investigation của TETRA-2134: 3 lỗi `F821 undefined-name` trong ruff baseline đều là cùng 1 nguyên nhân — `-> ModuleType` dùng làm return annotation nhưng `ModuleType` không được import. **Kết luận điều tra:** KHÔNG phải bug runtime — cả 3 file có `from __future__ import annotations` (Python 3.10) nên annotation bị hoãn thành string, không bao giờ eval khi import (đã xác nhận import sạch, exit 0). Nhưng vẫn là F821 thật: tham chiếu tên chưa định nghĩa, phá `typing.get_type_hints()`, ruff bắt đúng. **Fix:** thêm `from types import ModuleType` (đúng thứ tự isort, trước `from unittest.mock`) vào: - `test_asset_categories.py` - `test_asset_movement_custom_fields.py` - `test_setup_verification.py` ## Test Plan - [x] `ruff check --select F821 .` → All checks passed (3 → 0) - [x] `ModuleType` không bị F401 (được dùng trong annotation) - [x] 3 test file chạy từng file riêng: OK (5 + 6 + 14 test; 2 skipped) ## Ghi chú (baseline triage — đề xuất tách ticket riêng) Baseline ruff toàn repo hiện ~585 lỗi. Phân loại để đưa về 0 + bật full `ruff check` trong CI: - **RUF001/2/3** (~247): unicode tiếng Việt trong string/comment → nên **ignore** (repo VN, không phải lỗi). - **I001** (~157 import-sort) + **RUF100** (~66 noqa thừa): `ruff check --fix` autofix an toàn. - Còn lại (F401 unused như `sys`, lặt vặt): dọn thủ công từng nhóm. → Đề xuất follow-up ticket: set ignore-list RUF001/2/3, autofix I001/RUF100, dọn phần còn lại, rồi đổi CI gate từ `--select S110` sang full `ruff check`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fix(tests): TETRA-2134 — import ModuleType in 3 test files (clear ruff F821)
All checks were successful
Test (offline) / test (push) Successful in 33s
Test (offline) / test (pull_request) Successful in 38s
d70eabe34e
3 test file dùng `-> ModuleType` làm return annotation nhưng KHÔNG import
`ModuleType`. Cả 3 có `from __future__ import annotations` nên annotation
được hoãn (lazy string) → KHÔNG nổ runtime; nhưng vẫn là F821 thật
(undefined-name), phá `typing.get_type_hints()` và là tham chiếu sai.

Thêm `from types import ModuleType` (đúng thứ tự isort) vào:
- test_asset_categories.py
- test_asset_movement_custom_fields.py
- test_setup_verification.py

`ruff check --select F821 .` → All checks passed. 3 test file chạy OK
(5 + 6 + 14 test) từng file riêng.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tant merged commit a38283b7fc into main 2026-06-17 03:09:37 +07:00
tant deleted branch fix/TETRA-2134-f821-moduletype 2026-06-17 03:09:37 +07:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
tant/vhrms!165
No description provided.