{
  "id": "python/pytest-collection-error-modulenotfounderror",
  "signature": "ModuleNotFoundError: No module named 'tests'",
  "signature_zh": "ModuleNotFoundError: 没有名为 'tests' 的模块",
  "regex": "ModuleNotFoundError:\\ No\\ module\\ named\\ 'tests'",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "pytest cannot find the specified test module because the current working directory is not in sys.path or the module path is incorrect.",
  "root_cause_type": "generic",
  "root_cause_zh": "pytest 找不到指定的测试模块，因为当前工作目录不在 sys.path 中，或者模块路径不正确。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Modifying sys.path in conftest.py may not apply early enough during collection, and can cause inconsistent behavior across test runs.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The --pyargs flag requires the module to be installed as a package; otherwise it fails silently or raises the same error.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Run pytest from the project root directory or use the correct path: `pytest tests/`",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Set PYTHONPATH environment variable: `PYTHONPATH=. pytest`",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}