{
  "id": "python/pytest-monkeypatch-not-reverting",
  "signature": "AssertionError: assert 'original' == 'patched'",
  "signature_zh": "断言错误：断言'original'等于'patched'",
  "regex": "AssertionError:\\ assert\\ 'original'\\ ==\\ 'patched'",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "monkeypatch fixture在测试后未正确恢复原始值，导致后续测试受到影响。",
  "root_cause_type": "generic",
  "root_cause_zh": "monkeypatch未正确恢复，导致测试间状态污染。",
  "versions": [
    {
      "version": "3.6",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "容易遗漏，且与monkeypatch机制冲突。",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "pytest的monkeypatch自动处理，手动恢复可能重复。",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "def test_example(monkeypatch):\n    monkeypatch.setattr(module, 'attr', 'patched')\n    # 测试结束后自动恢复",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "with ExitStack() as stack:\n    stack.enter_context(patch('module.attr', 'patched'))",
      "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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-11-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}