{
  "id": "python/pytest-tmpdir-file-not-created",
  "signature": "FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pytest-of-user/pytest-0/test_foo0/somefile.txt'",
  "signature_zh": "文件未找到错误：没有这样的文件或目录",
  "regex": "FileNotFoundError:\\ \\[Errno\\ 2\\]\\ No\\ such\\ file\\ or\\ directory:\\ '/tmp/pytest\\-of\\-user/pytest\\-0/test_foo0/somefile\\.txt'",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "在测试中使用 tmpdir fixture 但未先创建文件，直接尝试读取或写入不存在的路径。",
  "root_cause_type": "generic",
  "root_cause_zh": "在测试中使用 tmpdir fixture 但未先创建文件，直接尝试读取或写入不存在的路径。",
  "versions": [
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "只创建目录不创建文件",
      "why_fails": "尝试使用 tmpdir.mkdir() 创建目录但忘记创建文件",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "open('subdir/file.txt', 'w')",
      "why_fails": "尝试使用 open() 写入但文件路径包含子目录且未创建",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "使用 tmpdir.join 自动创建",
      "success_rate": 0.95,
      "how": "file_path = tmpdir.join('file.txt')\nfile_path.write('content')",
      "condition": "",
      "sources": []
    },
    {
      "action": "手动创建目录",
      "success_rate": 0.85,
      "how": "import os\nos.makedirs(tmpdir, exist_ok=True)\nwith open(os.path.join(tmpdir, 'file.txt'), 'w') as f: f.write('x')",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-12",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}