首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pytest跳过测试提示"asyncio未安装“

Pytest跳过测试提示"asyncio未安装“
EN

Stack Overflow用户
提问于 2019-04-29 02:17:58
回答 1查看 7.3K关注 0票数 11

在测试以下代码时

代码语言:javascript
复制
@pytest.mark.asynico
async def test_handle_DATA(mocker):
    handle_mock = mocker.MagicMock()
    envelope_mock = mocker.MagicMock(mail_from="Test@From", rcpt_tos=["Test@To"], content=b"TestContent")

    result = SendToDictHandler.handle_DATA(handle_mock, "TestServer", "TestSession", envelope_mock)

    assert result == "250 Message accepted for delivery"
    assert email_core.testing_emails_dict == {
        "Test@To": {
            "from": "Test@From",
            "to": ["Test@To"],
            "msg": "TestContent",
        }
    }

在项目环境中运行pytest -vvv时收到的警告:

代码语言:javascript
复制
PytestWarning: Coroutine functions are not natively supported and have been skipped.
You need to install a suitable plugin for your async framework, for example:
 - pytest-asyncio
 - pytest-trio
 - pytest-tornasync
warnings.warn(PytestWarning(msg.format(pyfuncitem.nodeid)))

我确实安装了pytest-asyncio。我通过在项目的虚拟环境中运行pytest --trace-config进行了验证

代码语言:javascript
复制
================== test session starts ======================
platform win32 -- Python 3.7.1, pytest-4.4.1, py-1.8.0, pluggy-0.9.0
using: pytest-4.4.1 pylib-1.8.0
...
setuptools 
registered plugins:
 - pytest-randomly-3.0.0 at \lib\site-packages\pytest_randomly.py
 - pytest-mock-1.10.2 at \lib\site-packages\pytest_mock.py
 - pytest-asyncio-0.10.0 at \lib\site-packages\pytest_asyncio\plugin.py

active plugins:
 - pytest_mock         : \lib\site-packages\pytest_mock.py
 - asyncio             : \lib\site-packages\pytest_asyncio\plugin.py
...

plugins: randomly-3.0.0, mock-1.10.2, asyncio-0.10.0
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-29 04:06:21

我把这个问题留下来,以防其他人遇到这个问题。我最初的问题是在标记中拼写错了asynciopytest.mark.asyncio

一旦我修复了我需要等待我的响应,所以我不得不将我的测试更改为:

代码语言:javascript
复制
@staticmethod
@pytest.mark.asyncio
async def test_handle_DATA(mocker):
    handle_mock = mocker.MagicMock()
    envelope_mock = mocker.MagicMock(mail_from="Test@From", rcpt_tos=["Test@To"], content=b"TestContent")

    assert "250 Message accepted for delivery" == await SendToDictHandler.handle_DATA(
        handle_mock, "TestServer", "TestSession", envelope_mock
    )
    assert email_core.testing_emails_dict == {
        "Test@To": {
            "from": "Test@From",
            "to": ["Test@To"],
            "msg": "TestContent",
        }
    }
票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55893235

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档