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

Tom*_*all 2 python mocking pylint pytest python-3.x

测试示例:

import pytest
def test_do_stuff(mocker):
    import my_module
    mocker.patch.object(my_module, 'do_stuff')
    my_module.do_stuff.return_value = True
Run Code Online (Sandbox Code Playgroud)

皮林特反馈:

E1101: Function 'do_stuff' has no 'return_value' member (no-member)
Run Code Online (Sandbox Code Playgroud)

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

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

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

Tom*_*all 5

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

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