{
  "id": "python/pytest-doctest-import-failure",
  "signature": "ERROR collecting mypkg/mod.py\nE   ImportError: cannot import name 'helper' from 'mypkg.mod' (unknown location)",
  "signature_zh": "收集 mypkg/mod.py 时出错\nE   ImportError: 无法从 'mypkg.mod' 导入名称 'helper'（位置未知）",
  "regex": "ERROR\\ collecting\\ mypkg/mod\\.py\\\nE\\ \\ \\ ImportError:\\ cannot\\ import\\ name\\ 'helper'\\ from\\ 'mypkg\\.mod'\\ \\(unknown\\ location\\)",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "pytest --doctest-modules tries to import every module, including ones with side effects or circular imports, causing collection-time import errors.",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest --doctest-modules 会尝试导入每个模块，包括有副作用或循环导入的模块，导致收集阶段导入错误。",
  "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": "Skips doctests for that module entirely, losing coverage.",
      "fail_rate": 0.55,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The module still can't be imported due to the underlying circular import or missing dependency.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Fix the circular import by moving the import inside the function, or use `--doctest-modules` with `--import-mode=importlib`.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "Exclude problematic modules explicitly:\n[tool.pytest.ini_options]\naddopts = \"--doctest-modules --ignore=mypkg/cli.py\"",
      "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.8,
  "fix_success_rate": 0.8,
  "resolvable": "partial",
  "first_seen": "2024-09-25",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}