PyTest 产生警告 DeprecationWarning:没有当前事件循环

问题描述 投票:0回答:1

我已使用以下代码将 pytest-asyncio 添加到我的诗歌测试和开发组中:

    async def blah():
        return 1
    
    
    @pytest.mark.asyncio
    async def test_me(mock_client, mock_config, event_loop):
        res = await blah()
        assert 1 == res

当我运行

poetry run pytest
时,我收到此警告:

/Users/ykhaburzaniya/Library/Caches/pypoetry/virtualenvs/alakazam-6HJyiZWL-py3.11/lib/python3.11/site-packages/pytest_asyncio/plugin.py:884: DeprecationWarning: There is no current event loop
    _loop = asyncio.get_event_loop()

在我的诗歌.lock 中,我有 pytest-asyncio 版本 =“0.23.3”。

我该怎么做才能消除这个警告?

python pytest pytest-asyncio
1个回答
0
投票

Python 版本很重要。

目前,如果我在 3.11.0 中使用它,则会出现相同的警告,但在 3.11.7 以上时不会出现警告。

© www.soinside.com 2019 - 2024. All rights reserved.