gpt4 book ai didi

python - 如何让pylint识别模拟的方法成员?

转载 作者:太空宇宙 更新时间:2023-11-04 04:05:17 26 4
gpt4 key购买 nike

测试示例:

import pytest
def test_do_stuff(mocker):
import my_module
mocker.patch.object(my_module, 'do_stuff')
my_module.do_stuff.return_value = True

Pylint 反馈:

E1101: Function 'do_stuff' has no 'return_value' member (no-member)

这是不正确的,因为 my_module.do_stuff() 已被替换为支持此调用的模拟,但是,Pylint 似乎不理解这一点。

我可以使用测试文件顶部的 # pylint: disable=E1101 完全禁用非成员警告类型,但这也会隐藏合法的警告(例如,不正确的函数调用。)

有没有办法让 Pylint 与模拟对象一起工作?

最佳答案

据我所知,没有办法自动实现。

将 Pylint 禁用注释放在引发错误的行的末尾将仅抑制该行的警告并且不会停止对文件其余部分的分析,但注释将需要添加到每个有问题的行。

关于python - 如何让pylint识别模拟的方法成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57480608/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com