# RuntimeError: Working outside of application context.

- **ID:** `python/pytest-flask-app-context-missing`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (98% success)
   ```
   def test_something(app):
    with app.app_context():
        # code that uses current_app
        ...
   ```
2. **** (95% success)
   ```
   def test_something(app):
    with app.app_context():
        ...
   ```
3. **** (90% success)
   ```
   def test_request(client):
    response = client.get('/')
    ...
   ```

## Dead Ends

- **** — This enables testing mode but does not create an application context. (90% fail)
- **** — The context must be pushed (with app.test_request_context():) to be active. (85% fail)
- **** — This still requires an active context; it just returns the object if one exists. (95% fail)
