【问题标题】:Autocomplete pycharm doesn't work when using patch module in unittest在 unittest 中使用补丁模块时,自动完成 pycharm 不起作用
【发布时间】:2019-09-23 05:25:59
【问题描述】:

以下代码工作正常,这是一个模拟打印功能的非常简单的测试。问题是当我调用 mocked_print 并希望使用 assert_call_once_with 方法自动完成 mocked_print 时,编辑器的建议中不会出现。

Here's an image of the suggestions I get

环境:

  • Windows 10
  • PyCharm 社区版 2019.2.2
  • python 3.7.4.exe
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")

【问题讨论】:

    标签: python autocomplete mocking pycharm


    【解决方案1】:

    您可以导航到mock.patch 定义并看到它被键入为_patch 没有assert_called_once_with 的对象。

    PyCharm 使用来自typeshed 的存根用于unittest,因此似乎应该修改相应的存根。

    【讨论】:

    • 感谢您的回答,我对 Python/Pycharm 世界有点陌生,我仍然无法弄清楚这一点 - 这是否意味着 Pycharm 正在寻找错误的定义补丁?
    猜你喜欢
    • 1970-01-01
    • 2021-08-29
    • 2016-12-30
    • 1970-01-01
    • 2018-08-15
    • 2015-05-27
    • 2016-05-20
    • 2021-12-27
    • 2020-11-26
    相关资源
    最近更新 更多