{
  "id": "python/pytest-import-mismatch-conftest",
  "signature": "ImportError: import file mismatch:\n  'test_models.py' imported from /app/tests/unit/test_models.py\n  'test_models.py' imported from /app/tests/integration/test_models.py\nHint: make sure your test modules/packages have valid Python names.",
  "signature_zh": "ImportError: 导入文件不匹配:\n  'test_models.py' 从 /app/tests/unit/test_models.py 导入\n  'test_models.py' 从 /app/tests/integration/test_models.py 导入\n提示: 确保测试模块/包具有有效的 Python 名称。",
  "regex": "ImportError:\\ import\\ file\\ mismatch:\\\n\\ \\ 'test_models\\.py'\\ imported\\ from\\ /app/tests/unit/test_models\\.py\\\n\\ \\ 'test_models\\.py'\\ imported\\ from\\ /app/tests/integration/test_models\\.py\\\nHint:\\ make\\ sure\\ your\\ test\\ modules/packages\\ have\\ valid\\ Python\\ names\\.",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "Two test files share the same basename but live in different directories without __init__.py files, so pytest's rootdir-based module import collides and the second import fails.",
  "root_cause_type": "generic",
  "root_cause_zh": "两个测试文件同名但位于不同目录且没有 __init__.py 文件，pytest 基于 rootdir 的模块导入发生冲突，导致第二次导入失败。",
  "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": "Removes real test coverage; the collision returns as soon as another same-named file is added.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Fixes the single run but CI still uses the default mode and fails identically.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Add __init__.py to each test directory so pytest treats them as packages:\n\ntouch tests/unit/__init__.py tests/integration/__init__.py",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Or set import mode globally in pytest.ini:\n\n[pytest]\naddopts = --import-mode=importlib",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-27",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}