{
  "id": "python/pytest-import-error-same-name",
  "signature": "ImportError: import file mismatch:\nimported module 'test_utils' has this __file__ attribute:\n  /path/to/other/test_utils.py\nwhich is not the same as the test file we want to collect:",
  "signature_zh": "导入错误：导入文件不匹配：导入的模块 'test_utils' 的 __file__ 属性与要收集的测试文件不一致",
  "regex": "ImportError:\\ import\\ file\\ mismatch:\\\nimported\\ module\\ 'test_utils'\\ has\\ this\\ __file__\\ attribute:\\\n\\ \\ /path/to/other/test_utils\\.py\\\nwhich\\ is\\ not\\ the\\ same\\ as\\ the\\ test\\ file\\ we\\ want\\ to\\ collect:",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "存在多个同名测试模块，pytest 导入时发生冲突，通常因为目录结构或 __init__.py 问题。",
  "root_cause_type": "generic",
  "root_cause_zh": "存在多个同名测试模块，pytest 导入时发生冲突，通常因为目录结构或 __init__.py 问题。",
  "versions": [
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "删除重复文件",
      "why_fails": "尝试删除其中一个文件，但可能破坏测试逻辑",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "修改 sys.path",
      "why_fails": "尝试在 conftest.py 中修改 sys.path 但未解决根本问题",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "创建 __init__.py",
      "success_rate": 0.85,
      "how": "在相关目录中添加 __init__.py 文件，确保包结构清晰",
      "condition": "",
      "sources": []
    },
    {
      "action": "pytest --import-mode=importlib",
      "success_rate": 0.9,
      "how": "使用 --import-mode=importlib 运行 pytest",
      "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.83,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-08-20",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}