{
  "id": "python/pytest-tmp-path-permission-denied",
  "signature": "PermissionError: [Errno 13] Permission denied: '/tmp/pytest-of-root/pytest-0/test_write_file0/output.txt'",
  "signature_zh": "PermissionError: [Errno 13] 权限被拒绝：'/tmp/pytest-of-root/pytest-0/test_write_file0/output.txt'",
  "regex": "PermissionError:\\ \\[Errno\\ 13\\]\\ Permission\\ denied:\\ '/tmp/pytest\\-of\\-root/pytest\\-0/test_write_file0/output\\.txt'",
  "domain": "python",
  "category": "system_error",
  "subcategory": null,
  "root_cause": "A previous pytest run as root created tmp_path directories owned by root under /tmp/pytest-of-<user>/. A subsequent run as a non-root user cannot write into those directories.",
  "root_cause_type": "generic",
  "root_cause_zh": "之前以 root 身份运行的 pytest 在 /tmp/pytest-of-<user>/ 下创建了由 root 拥有的 tmp_path 目录。随后以非 root 用户运行时无法写入这些目录。",
  "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": "Only fixes this run; the next pytest invocation creates a new numbered directory with the same root ownership problem.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "pytest still uses /tmp/pytest-of-<user>, so the ownership collision persists.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "rm -rf /tmp/pytest-of-$(whoami)\n# or, if owned by root:\nsudo rm -rf /tmp/pytest-of-root\npytest tests/",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "pytest --basetemp=/home/$(whoami)/pytest-tmp tests/\n# or in pyproject.toml:\n# [tool.pytest.ini_options]\n# basetemp = \"/home/me/pytest-tmp\"",
      "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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-11-03",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}