在 python 2.7 中,我有这个功能
from slacker import Slacker
def post_message(token, channel, message):
channel = '#{}'.format(channel)
slack = Slacker(token)
slack.chat.post_message(channel, message)
使用模拟和补丁,我可以检查令牌是否在 Slacker 类中使用
import unittest
from mock import patch
from slacker_cli import post_message
class TestMessage(unittest.TestCase):
@patch('slacker_cli.Slacker')
def test_post_message_use_token(self, mock_slacker):
token = 'aaa'
channel = 'channel_name'
message = 'message string'
post_message(token, channel, message)
mock_slacker.assert_called_with(token)
如何检查 post_message 中的字符串使用情况?
我尝试
mock_slacker.chat.post_message.assert_called_with('#channel_name')
但我明白了
AssertionError: Expected call: post_message('#channel_name')
Not called