以下代码工作正常,这是模拟打印功能的非常简单的测试。问题是当我调用 mocked_print 并希望自动完成 mocked_print 时,assert_called_once_with 方法没有出现在编辑器的建议中。
Here's an image of the suggestions I get
环境:
import unittest
from unittest import mock
def print_something():
print('Hello')
class TestFoo(unittest.TestCase):
def test_print(self):
with mock.patch('builtins.print') as mocked_print:
print_something()
mocked_print.assert_called_once_with("Hello")
最佳答案
您可以导航到 mock.patch
定义并看到它被类型化为没有 assert_called_once_with
的 _patch
对象。
PyCharm 使用来自 typeshed 的 stub 对于 unittest
所以似乎应该修改相应的 stub 。
https://stackoverflow.com/questions/58032232/