{
  "id": "python/pytest-collection-error-import-mismatch",
  "signature": "E   ImportError: cannot import name 'app' from 'myapp' (/path/to/myapp/__init__.py)",
  "signature_zh": "E   ImportError: 无法从 'myapp' 导入名称 'app' (/path/to/myapp/__init__.py)",
  "regex": "E\\ \\ \\ ImportError:\\ cannot\\ import\\ name\\ 'app'\\ from\\ 'myapp'\\ \\(/path/to/myapp/__init__\\.py\\)",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "pytest fails to collect tests because a test module imports a name that doesn't exist in the target module. This often occurs due to circular imports, missing __init__.py, or incorrect package structure.",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest无法收集测试，因为测试模块导入了目标模块中不存在的名称。这通常是由于循环导入、缺少 __init__.py 或包结构不正确造成的。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This creates a dummy import that may hide the real issue and break other parts of the application.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This skips all tests, providing no validation and defeating the purpose of testing.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Relative imports only work within packages and may cause issues when running tests from different directories.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Check myapp/__init__.py and myapp/app.py:\n\n# myapp/__init__.py\nfrom .app import app\n\nEnsure the app object is defined in myapp/app.py.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Run: pip install -e .\nThen in tests, use: from myapp import app",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "In conftest.py:\n\nimport sys\nfrom pathlib import Path\nsys.path.insert(0, str(Path(__file__).parent.parent))",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}