# RuntimeError: 没有正在运行的事件循环
  文件 ".../pytest_asyncio/plugin.py"，行 ...，在 pytest_pyfunc_call 中
    result = loop.run_until_complete(...)

- **ID:** `python/pytest-asyncio-no-running-loop`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

异步测试被收集但未标记 @pytest.mark.asyncio，或者 pytest-asyncio 模式设置为 'strict'（默认）且缺少标记。插件拒绝运行该协程。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   import pytest

@pytest.mark.asyncio
async def test_fetch():
    result = await fetch()
    assert result == 42
   ```
2. **** (92% 成功率)
   ```
   # pyproject.toml
[tool.pytest.ini_options]
asyncio_mode = "auto"

# or pytest.ini
# [pytest]
# asyncio_mode = auto
   ```

## 无效尝试

- **** — pytest-asyncio already manages the loop; calling asyncio.run() inside a coroutine raises 'asyncio.run() cannot be called from a running event loop'. (80% 失败率)
- **** — If pytest reads pyproject.toml instead, the config is ignored and strict mode persists. (60% 失败率)
