{
  "id": "python/pytest-import-mismatch-local-module",
  "signature": "E   ModuleNotFoundError: No module named 'tests.test_utils'",
  "signature_zh": "E   ModuleNotFoundError: 没有名为 'tests.test_utils' 的模块",
  "regex": "E\\ \\ \\ ModuleNotFoundError:\\ No\\ module\\ named\\ 'tests\\.test_utils'",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "A test module tries to import another test module as a package, but the tests directory is not a package (missing __init__.py) or the import path is incorrect.",
  "root_cause_type": "generic",
  "root_cause_zh": "测试模块尝试将另一个测试模块作为包导入，但 tests 目录不是包（缺少 __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 makes tests a package but can cause import conflicts with pytest's rootdir and may break other imports.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Relative imports only work within packages; if tests is not a package, this fails.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This is brittle and may not work consistently across different working directories.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "In conftest.py at project root:\n\nimport sys\nfrom pathlib import Path\nsys.path.insert(0, str(Path(__file__).parent))",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "pip install -e .\nThen in tests: from mypackage.tests.test_utils import helper",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Create a test_utils package at the project root and import from it:\nfrom test_utils import helper",
      "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": "2025-04-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}