{
  "id": "python/pytest-conftest-import-shadowing",
  "signature": "ImportError: cannot import name 'helpers' from partially initialized module 'tests' (most likely due to a circular import)",
  "signature_zh": "ImportError: 无法从部分初始化的模块 'tests' 导入名称 'helpers'（很可能是由于循环导入）",
  "regex": "ImportError:\\ cannot\\ import\\ name\\ 'helpers'\\ from\\ partially\\ initialized\\ module\\ 'tests'\\ \\(most\\ likely\\ due\\ to\\ a\\ circular\\ import\\)",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "Two conftest.py files in nested test directories import the same helper module that itself imports from the test package, creating a cycle during pytest collection.",
  "root_cause_type": "generic",
  "root_cause_zh": "嵌套测试目录中的两个 conftest.py 导入同一个 helper 模块，而该模块又从测试包导入，导致 pytest 收集期间形成循环。",
  "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": "Making tests a package can change rootdir behavior and does not break the import cycle between helpers and conftest.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Deferred import still triggers the cycle if helpers imports from tests at module load time.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "# Layout:\n# tests/conftest.py\n# tests/helpers.py  <-- imports tests.something (cycle)\n# Fix: move helpers to project root\n# helpers.py\nimport sys, pathlib\nsys.path.insert(0, str(pathlib.Path(__file__).parent))\nimport helpers",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "# tests/conftest.py\n@pytest.fixture\ndef client():\n    from tests.helpers import make_client  # imported at call time\n    return make_client()",
      "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.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-04-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}