{
  "id": "python/pytest-tmp-path-not-shared",
  "signature": "FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pytest-of-root/pytest-12/test_write0/data.json'",
  "signature_zh": "FileNotFoundError: [Errno 2] 没有那个文件或目录: '/tmp/pytest-of-root/pytest-12/test_write0/data.json'",
  "regex": "FileNotFoundError:\\ \\[Errno\\ 2\\]\\ No\\ such\\ file\\ or\\ directory:\\ '/tmp/pytest\\-of\\-root/pytest\\-12/test_write0/data\\.json'",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "`tmp_path` is function-scoped and unique per test; a file written in one test is not visible in another because each test gets a fresh numbered directory.",
  "root_cause_type": "generic",
  "root_cause_zh": "`tmp_path` 是 function 作用域且每个测试唯一；一个测试写入的文件在另一个测试中不可见，因为每个测试获得新的编号目录。",
  "versions": [
    {
      "version": "7.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "8.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Breaks isolation and parallel runs; tests collide and leave stale state.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Parent is the per-run root shared by all tests in the session; writing there risks collisions under xdist.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use `tmp_path_factory` for a session-scoped shared dir:\n@pytest.fixture(scope='session')\ndef shared_data(tmp_path_factory):\n    p = tmp_path_factory.mktemp('shared')\n    (p / 'data.json').write_text('{}')\n    return p",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Or pass the path explicitly from the producing test to the consumer via a fixture dependency chain.",
      "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-02-09",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}