测试以下代码时
@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
时收到的警告:
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
进行验证
================== 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
我把这个问题留着处理,以免别人碰到这个问题。我最初的问题是在标记中
asyncio
拼错了:pytest.mark.asyncio
一旦我确定我需要等待我的回答,所以我不得不将我的测试改为:
相关问题 更多 >
编程相关推荐