{
  "id": "python/pytest-import-mode-conflict",
  "signature": "import file mismatch:\ntests/test_a.py has __pycache__ but tests/test_a.py has different __pycache__\nHINT: remove __pycache__ files or use --import-mode=importlib",
  "signature_zh": "导入文件不匹配：\ntests/test_a.py 有 __pycache__ 但 tests/test_a.py 有不同的 __pycache__\n提示：删除 __pycache__ 文件或使用 --import-mode=importlib",
  "regex": "import\\ file\\ mismatch:\\\ntests/test_a\\.py\\ has\\ __pycache__\\ but\\ tests/test_a\\.py\\ has\\ different\\ __pycache__\\\nHINT:\\ remove\\ __pycache__\\ files\\ or\\ use\\ \\-\\-import\\-mode=importlib",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "Two test files share the same module basename (e.g. tests/api/test_a.py and tests/db/test_a.py) and neither directory has an __init__.py, so pytest's prepend import mode collides on the module name.",
  "root_cause_type": "generic",
  "root_cause_zh": "两个测试文件共享相同的模块基名（例如 tests/api/test_a.py 和 tests/db/test_a.py），且两个目录都没有 __init__.py，因此 pytest 的 prepend 导入模式在模块名上冲突。",
  "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": "Clears the symptom for one run; the next run recreates the collision.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Works but does not scale; the next same-named file reintroduces the problem.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "# pytest.ini\n[pytest]\nimportmode = importlib",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "touch tests/__init__.py tests/api/__init__.py tests/db/__init__.py",
      "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-06-03",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}