{
  "id": "python/pytest-httpserver-port-in-use",
  "signature": "OSError: [Errno 98] Address already in use\n  during setup of tests/test_http.py::test_fetch\n  port 8080 is already bound",
  "signature_zh": "OSError: [Errno 98] 地址已被占用\n  在 tests/test_http.py::test_fetch 的设置期间\n  端口 8080 已被占用",
  "regex": "OSError:\\ \\[Errno\\ 98\\]\\ Address\\ already\\ in\\ use\\\n\\ \\ during\\ setup\\ of\\ tests/test_http\\.py::test_fetch\\\n\\ \\ port\\ 8080\\ is\\ already\\ bound",
  "domain": "python",
  "category": "network_error",
  "subcategory": null,
  "root_cause": "A previous test run or another process is still holding the port. Common with pytest-httpserver, responses, or a local dev server started in a session-scoped fixture that was not torn down.",
  "root_cause_type": "generic",
  "root_cause_zh": "之前的测试运行或其他进程仍占用该端口。在使用 pytest-httpserver、responses 或在 session 作用域 fixture 中启动但未拆除的本地开发服务器时很常见。",
  "versions": [
    {
      "version": "1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Next run someone else uses 8081; whack-a-mole with no root fix and CI containers may have different free ports.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The port stays bound between retries; retries fail immediately.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.97,
      "how": "from pytest_httpserver import HTTPServer\n\ndef test_fetch(httpserver: HTTPServer):\n    httpserver.expect_request('/api').respond_with_json({'ok': True})\n    url = httpserver.url_for('/api')  # uses assigned port\n    assert fetch(url) == {'ok': True}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "@pytest.fixture(scope='session')\ndef server():\n    srv = HTTPServer()\n    srv.start()\n    yield srv\n    srv.stop()  # critical",
      "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.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-27",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}