如何在我的代码上编写 pytest 或 unittest?
How to write a pytest or unittest on my code?
我是单元测试的新手。我正在尝试测试是否调用了函数以及下面的计划时间是否正确。
The python filename is #schedule.py
def screenshot():
ob=Screenshot_Clipping.Screenshot()
driver.get(url)
img_url=ob.full_Screenshot(driver, save_path = path)
email_it(path)
driver.close()
screenshot()
试试这个,
def test_screenshot(mocker):
url = 'url'
path = /your/path/
mocker.patch('screenshot.env', return_value = (url, path))
mocker.patch('screenshot.email_it', return_value = (path))
screenshot()
我是单元测试的新手。我正在尝试测试是否调用了函数以及下面的计划时间是否正确。
The python filename is #schedule.py
def screenshot():
ob=Screenshot_Clipping.Screenshot()
driver.get(url)
img_url=ob.full_Screenshot(driver, save_path = path)
email_it(path)
driver.close()
screenshot()
试试这个,
def test_screenshot(mocker):
url = 'url'
path = /your/path/
mocker.patch('screenshot.env', return_value = (url, path))
mocker.patch('screenshot.email_it', return_value = (path))
screenshot()