簡體   English   中英

在單元測試中使用補丁模塊時,自動完成 pycharm 不起作用

[英]Autocomplete pycharm doesn't work when using patch module in unittest

以下代碼工作正常,這是一個非常簡單的測試來模擬打印 function。 問題是當我調用 mocked_print 並希望使用assert_called_once_with方法自動完成mocked_print時,編輯器的建議中沒有出現。

這是我得到的建議的圖像

環境:

  • 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")

您可以導航到mock.patch定義並看到它的類型為_patch object 沒有assert_called_once_with

unittest使用typeshed的存根進行單元測試,因此似乎應該修改相應的存根。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM