From fab03a79cff7f48e35c83d4e23101a91538e48d3 Mon Sep 17 00:00:00 2001 From: saas-backend-agent Date: Mon, 7 Sep 2026 08:35:53 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BF=AE=E4=B8=A4=E4=B8=AA=20CI=20flak?= =?UTF-8?q?y=20=E6=B5=8B=E8=AF=95=EF=BC=88=E4=B8=8E=20#1749=20=E6=97=A0?= =?UTF-8?q?=E5=85=B3=EF=BC=8C=E9=A1=BA=E5=B8=A6=E4=BF=AE=E8=AE=A9=20CI=20G?= =?UTF-8?q?ate=20=E8=BF=87=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - test_auth_bind_wechat_sync:默认昵称 '微信用户' → '小虾同学'(use case 已改,测试未同步) - test_smart_match_noise_1743:patch datetime.now 为 NOW,避免 recency 分数随真实时间漂移导致断言失败 --- tests/unit/test_auth_bind_wechat_sync.py | 2 +- tests/unit/test_smart_match_noise_1743.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_auth_bind_wechat_sync.py b/tests/unit/test_auth_bind_wechat_sync.py index e11a41e7f..a311350da 100755 --- a/tests/unit/test_auth_bind_wechat_sync.py +++ b/tests/unit/test_auth_bind_wechat_sync.py @@ -656,7 +656,7 @@ class TestWechatSyncUseCase: assert error is None assert response.is_new_user is True - assert response.nickname == "微信用户" + assert response.nickname == "小虾同学" def test_username_uniqueness_suffix(self): """When username already exists, a numeric suffix is added.""" diff --git a/tests/unit/test_smart_match_noise_1743.py b/tests/unit/test_smart_match_noise_1743.py index 0fc5c3a1b..ab1c7bc3c 100644 --- a/tests/unit/test_smart_match_noise_1743.py +++ b/tests/unit/test_smart_match_noise_1743.py @@ -84,11 +84,18 @@ class TestScoreNoiseInjection: def test_score_field_is_raw_without_noise(self): """r.score 始终是无噪声原始分(噪声只影响排序,不污染返回分值)。""" + from unittest.mock import patch + from datetime import datetime as _dt assets = _make_tied_assets(5) raw_scores = {score_asset(a, now=NOW)[0] for a in assets} - results = smart_select_assets(assets, rng=random.Random(42)) + # 冻结 datetime.now,与 score_asset 用的 NOW 一致(recency 时变分数需稳定) + with patch("packages.domain.smart_match.datetime") as mock_dt: + mock_dt.now.return_value = NOW + # 保留 datetime 构造函数行为(如 datetime(...) 调用) + mock_dt.side_effect = _dt + results = smart_select_assets(assets, rng=random.Random(42)) for r in results: - assert r.score in raw_scores + assert r.score in raw_scores, f"score={r.score} 不在 raw_scores={raw_scores}" def test_rng_deterministic_same_seed(self): """同一种子多次调用结果完全一致(可复现,测试可依赖)。"""