fix(ci): 日志停用测试适配 Python 3.12.9+ 空文件不滚动 (gh-116263)

CI (Python 3.12) 挂在本机 (3.11) 通过的用例上: gh-116263 给 shouldRollover 加了「空文件永不滚动」守卫, 新 attach 的 handler 指向空文件时首条日志不触发滚动, rotate/handleError 根本不执行。测试预置 100 字节内容使首条日志即滚动, 3.11/3.12 双版本验证通过。产品代码不受影响 (生产滚动时文件必然非空)。
This commit is contained in:
shy3130
2026-10-28 08:15:47 +08:00
parent 88141def9a
commit 1cb9c7c69c
+4
View File
@@ -123,6 +123,10 @@ def test_persistent_rotate_failure_disables_handler(data_dir, no_leaked_handlers
handler = [h for h in logging.getLogger().handlers
if isinstance(h, logfile.StallSafeRotatingFileHandler)][-1]
handler.maxBytes = 60
# gh-116263 (Python 3.12.9+): 空文件永不滚动 — 预置内容让首条日志即触发滚动,
# 否则 3.12 上 shouldRollover 直接 False, rotate/handleError 根本不会执行
handler.stream.write("-" * 100 + "\n")
handler.stream.flush()
def boom(src, dest):
raise OSError(32, "另一个程序正在使用此文件")