{
  "id": "python/pytest-import-mismatch-missing-init",
  "signature": "import file mismatch:\n  /app/tests/test_models.py has this __file__ attribute:\n    /app/tests/test_models.py\n  which is not the same as the test file we want to collect:\n    /app/tests/unit/test_models.py\nHINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules",
  "signature_zh": "导入文件不匹配：\n  /app/tests/test_models.py 的 __file__ 属性为：\n    /app/tests/test_models.py\n  与要收集的测试文件不同：\n    /app/tests/unit/test_models.py\n提示：删除 __pycache__ / .pyc 文件，和/或为测试文件模块使用唯一的基名",
  "regex": "import\\ file\\ mismatch:\\\n\\ \\ /app/tests/test_models\\.py\\ has\\ this\\ __file__\\ attribute:\\\n\\ \\ \\ \\ /app/tests/test_models\\.py\\\n\\ \\ which\\ is\\ not\\ the\\ same\\ as\\ the\\ test\\ file\\ we\\ want\\ to\\ collect:\\\n\\ \\ \\ \\ /app/tests/unit/test_models\\.py\\\nHINT:\\ remove\\ __pycache__\\ /\\ \\.pyc\\ files\\ and/or\\ use\\ a\\ unique\\ basename\\ for\\ your\\ test\\ file\\ modules",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "Two test files share the same basename (test_models.py) in different directories, but neither directory is a Python package (no __init__.py), so pytest imports both as top-level module `test_models`, causing a collision.",
  "root_cause_type": "generic",
  "root_cause_zh": "两个测试文件在不同目录下共享相同基名（test_models.py），但两个目录都不是 Python 包（缺少 __init__.py），因此 pytest 将两者都作为顶层模块 `test_models` 导入，导致冲突。",
  "versions": [
    {
      "version": "6.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "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": "Clearing caches removes stale bytecode but does not fix the underlying module-name collision; the error reappears on the next run.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Changing PYTHONPATH does not give the two files distinct module names; the collision is due to identical basenames without package context.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "touch tests/__init__.py tests/unit/__init__.py\n# pytest then imports as tests.test_models and tests.unit.test_models",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "mv tests/test_models.py tests/test_api_models.py\nmv tests/unit/test_models.py tests/unit/test_db_models.py",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "# pytest.ini\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.89,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-02-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}