【发布时间】:2023-03-26 18:24:01
【问题描述】:
我是一名初级程序员,过去一周我一直在尝试编写单元测试。我通读了单元测试文档并观看了两个关于使用Mock 实现单元测试的长教程。文档广泛引用了模拟类,但对于函数,我不确定是否应该使用@patch/with patch、patch.dict{}、side_effect 或其他一些选项来模拟函数,特别是函数的参数。
mymodule.py
def regex():
'''Runs a regex, creates a dict 'data' and then calls scraper(data)'''
def scraper(data):
'''scrapes a website and then calls a function which submits data to a db'''
我想创建一个将测试数据传递给函数 scraper 的测试。提前谢谢你。
【问题讨论】:
标签: python unit-testing mocking