# RuntimeError: There is no current event loop in thread 'MainThread'.

- **ID:** `python/unittest-isolated-asyncio-testcase`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Using unittest.IsolatedAsyncioTestCase with code that calls asyncio.get_event_loop() from a non-async context, or mixing sync and async test methods incorrectly.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   class TestX(unittest.IsolatedAsyncioTestCase):
    async def test_y(self):
        loop = asyncio.get_running_loop()
        await loop.create_task(coro())
   ```
2. **** (90% success)
   ```
   class TestX(unittest.IsolatedAsyncioTestCase):
    async def test_y(self):
        loop = asyncio.get_running_loop()
        result = await my_func(loop=loop)
        self.assertEqual(result, 1)
   ```

## Dead Ends

- **** — IsolatedAsyncioTestCase manages its own loop; overriding it causes 'loop already running' or leaks loops between tests. (85% fail)
- **** — Works for simple cases but breaks async fixtures and shares no loop with the test's async methods. (60% fail)
- **** — IsolatedAsyncioTestCase exists from 3.8; downgrading does not change the event-loop lookup behavior. (95% fail)
