【发布时间】:2021-12-29 02:15:41
【问题描述】:
@pytest.fixture
def d_service():
c = DService()
return c
# @pytest.mark.asyncio # tried it too
async def test_get_file_list(d_service):
files = await d_service.get_file_list('')
print(files)
但是,它得到了以下错误?
收集到 0 个项目 / 1 个错误 ==================================== 错误============== ======================= ________________ 错误收集测试/e2e_tests/test_d.py _________________ ..\..\..\..\..\anaconda3\lib\site-packages\pluggy\__init__.py:617: 在 __call__ return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) ..\..\..\..\..\anaconda3\lib\site-packages\pluggy\__init__.py:222:在 _hookexec return self._inner_hookexec(hook, methods, kwargs) ..\..\..\..\..\anaconda3\lib\site-packages\pluggy\__init__.py:216: 在 firstresult=hook.spec_opts.get('firstresult'), ..\..\..\..\..\anaconda3\lib\site-packages\_pytest\python.py:171:在 pytest_pycollect_makeitem res = 结果.get_result() ..\..\..\..\..\anaconda3\lib\site-packages\anyio\pytest_plugin.py:98:在 pytest_pycollect_makeitem 标记 = collector.get_closest_marker('anyio') E AttributeError:“模块”对象没有属性“get_closest_marker” !!!!!!!!!!!!!!!!!!中断:收集期间出现 1 个错误!!!!!!!!!!!!!!!!!!! ============================ 2.53 秒内出现 1 个错误 ================== =========我安装了以下软件包。错误消失但测试被跳过。
pip install pytest-asyncio
(基础)PS>pytest -s 测试\e2e_tests\test_d.py
==================================================== ==================================================== ============== 测试开始 ================================= ==================================================== =================================
平台 win32 -- Python 3.6.4、pytest-6.2.5、py-1.11.0、pluggy-1.0.0
根目录:C:\Users\X01324908\source\rds\research_data_science\sftp\file_handler
插件:anyio-3.3.4、asyncio-0.16.0
收集了 1 件物品
测试\e2e_tests\test_d.py s
==================================================== ==================================================== ================ 警告总结 ================================ ==================================================== ====================================
测试/e2e_tests/test_d.py::test_get_file_list
c:\users\x01324908\anaconda3\lib\site-packages\_pytest\python.py:172: PytestUnhandledCoroutineWarning: async def 函数不受本机支持,已被跳过。
您需要为您的异步框架安装合适的插件,例如:
- 随便
- pytest-asyncio
- pytest-tornasync
- pytest 三重奏
- pytest 扭曲
warnings.warn(PytestUnhandledCoroutineWarning(msg.format(nodeid)))
-- 文档:https://docs.pytest.org/en/stable/warnings.html
==============
【问题讨论】:
-
你的 pytest 版本是什么?
-
更新了问题。版本是6.2.5
-
关于收集错误 - 您的项目布局中一定有一些可疑之处。你能加一个minimal reproducible example吗?除此之外:如果你想用
anyio/asyncio运行测试,你必须用pytest.mark.anyio/pytest.mark.asyncio标记它们。否则,将跳过异步测试并显示(有点误导)警告 - 这是正确的行为。