{
  "id": "python/pytest-flask-app-context-missing",
  "signature": "RuntimeError: Working outside of application context.",
  "signature_zh": "RuntimeError: 在应用程序上下文之外工作。",
  "regex": "RuntimeError:\\ Working\\ outside\\ of\\ application\\ context\\.",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A test tries to access Flask's current_app or other context-local objects without an active application context. This often occurs when testing code that uses Flask globals outside a request or app context.",
  "root_cause_type": "generic",
  "root_cause_zh": "测试尝试访问 Flask 的 current_app 或其他上下文局部对象，但没有活动的应用程序上下文。这通常发生在测试使用 Flask 全局变量的代码时，不在请求或应用上下文中。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This enables testing mode but does not create an application context.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The context must be pushed (with app.test_request_context():) to be active.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This still requires an active context; it just returns the object if one exists.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.98,
      "how": "def test_something(app):\n    with app.app_context():\n        # code that uses current_app\n        ...",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "def test_something(app):\n    with app.app_context():\n        ...",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "def test_request(client):\n    response = client.get('/')\n    ...",
      "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.89,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-07-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}