【发布时间】:2017-09-16 19:30:54
【问题描述】:
我必须测试是否调用了 pyautogui.click() 方法。这是我的 Player.py 文件:
# Player.py
import pyautogui
class Player:
def play():
pyautogui.click(100, 100)
这是我的测试文件:
# Test_Player.py
import unittest
from Player import Player
class Test_Player(unittest.TestCase):
def test_play(self):
player = Player()
player.play()
# assert pyautogui.click is called once
我尝试了pyautogui.click = MagicMock() 以及许多其他东西,但我真的找不到如何断言 pyautogui.click() 被调用一次。
【问题讨论】:
-
我推荐你read the docs。至少给一个minimal reproducible example。
标签: python unit-testing mocking tdd