{
  "id": "python/unittest-mock-patch-decorator-order",
  "signature": "TypeError: test_foo() missing 1 required positional argument: 'mock_bar'",
  "signature_zh": "TypeError: test_foo() 缺少 1 个必需的位置参数: 'mock_bar'",
  "regex": "TypeError:\\ test_foo\\(\\)\\ missing\\ 1\\ required\\ positional\\ argument:\\ 'mock_bar'",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "When using multiple @patch decorators, the mocks are passed in bottom-up order. If the test function signature does not match, a TypeError occurs.",
  "root_cause_type": "generic",
  "root_cause_zh": "使用多个 @patch 装饰器时，mock 按从下到上的顺序传递。如果测试函数签名不匹配，会发生 TypeError。",
  "versions": [
    {
      "version": "3.8",
      "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": "This hides the error but makes the test less clear and may cause issues with assertions.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This may not be possible if multiple dependencies need mocking.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "@patch('module.ClassB')\n@patch('module.ClassA')\ndef test_foo(mock_a, mock_b):  # mock_a corresponds to bottom decorator\n    ...",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.98,
      "how": "def test_foo():\n    with patch('module.ClassA') as mock_a, \\\n         patch('module.ClassB') as mock_b:\n        ...",
      "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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}