{
  "id": "python/pytest-mock-reset-between-calls",
  "signature": "AssertionError: Expected 'send_email' to be called once. Called 0 times.",
  "signature_zh": "AssertionError: 期望 'send_email' 被调用一次。实际调用 0 次。",
  "regex": "AssertionError:\\ Expected\\ 'send_email'\\ to\\ be\\ called\\ once\\.\\ Called\\ 0\\ times\\.",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The test asserts `mock.assert_called_once()` but the mock was reset (e.g. by `mock.reset_mock()` or a fixture that resets it) before the assertion, or the code under test was patched at the wrong target.",
  "root_cause_type": "generic",
  "root_cause_zh": "测试断言 `mock.assert_called_once()`，但 mock 在断言前被重置（例如被 `mock.reset_mock()` 或某个 fixture 重置），或者被测代码 patch 了错误的目标。",
  "versions": [
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Still fails if the mock was never called; masks the real issue.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Repeating the assertion does not change the call count.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Patch where the name is looked up and verify the patch target:\n\n@patch('app.services.user.send_email')\ndef test_signup(mock_send):\n    signup()\n    mock_send.assert_called_once()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Remove any `reset_mock()` calls between the action and the assertion, or use `mock.call_count` to inspect at the exact point.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-12-12",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}