{
  "id": "python/pytest-import-mismatch-src-layout",
  "signature": "ModuleNotFoundError: No module named 'myapp'\n# when running pytest from repo root with src/ layout",
  "signature_zh": "ModuleNotFoundError: 没有名为 'myapp' 的模块\n# 使用 src/ 布局从仓库根运行 pytest 时",
  "regex": "ModuleNotFoundError:\\ No\\ module\\ named\\ 'myapp'\\\n\\#\\ when\\ running\\ pytest\\ from\\ repo\\ root\\ with\\ src/\\ layout",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "src/ layout requires the package to be installed or on sys.path; running pytest from the repo root without `pip install -e .` leaves src/myapp unreachable.",
  "root_cause_type": "generic",
  "root_cause_zh": "src/ 布局要求包已安装或在 sys.path 上；未执行 `pip install -e .` 时从仓库根运行 pytest 无法访问 src/myapp。",
  "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": "Duplicated boilerplate and still fails for subprocess-based tests or coverage tools that re-import.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Abandons src/ layout benefits (isolation, editable install correctness) and may break packaging.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Not reproducible in CI; each developer must remember the env var.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.98,
      "how": "pip install -e .\n# or with build backend\npip install -e \".[test]\"\n\n# then\npytest",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "# pyproject.toml\n[tool.pytest.ini_options]\npythonpath = [\"src\"]\ntestpaths = [\"tests\"]",
      "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": "2025-06-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}