python data_error ai_generated true

snapshot_assertion_failed: 快照 'test_render' 不匹配。 接收值与存储的快照不匹配。 使用 --snapshot-update 重新生成。

snapshot_assertion_failed: Snapshot 'test_render' does not match. Received value does not match the stored snapshot. Use --snapshot-update to regenerate.

ID: python/pytest-snapshot-mismatch

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2025-10-25首次发现

版本兼容性

版本状态引入弃用备注
0.9 active

根因分析

快照测试(pytest-snapshot、syrupy、snapshottest)将输出与存储文件比较;输出任何变化(有意或无意)都会导致不匹配。

English

snapshot testing (pytest-snapshot, syrupy, snapshottest) compares output to a stored file; any change in output (intentional or not) causes a mismatch.

generic

解决方案

  1. 95% 成功率
    pytest tests/test_render.py -k test_render --snapshot-details
    # review the diff, then
    pytest --snapshot-update tests/test_render.py
  2. 90% 成功率
    def sanitize(output):
        output.pop('timestamp', None)
        output['id'] = '<id>'
        return output
    
    def test_render(snapshot):
        snapshot.assert_match(sanitize(render()), 'render.json')

无效尝试

常见但无效的做法:

  1. 90% 失败

    Accepts whatever the code currently produces, including regressions; snapshots become rubber stamps.

  2. 85% 失败

    Next run recreates it from current (possibly buggy) output, losing the historical baseline.

  3. 80% 失败

    Hides the diff and prevents catching real regressions; xfail state tends to linger.