我在用模块pytest做测试
问题:当我运行pytest时,它可以正常工作,但是如何阻止它调用我正在测试的函数中的函数呢
例如
def download_csv(self):
# code here will download csv
# I want to test code up until here and dont run the decompress_csv() function
self.decompress_csv()
# assume this function is in a separate test file
def test_download_csv():
assert download_csv() == # i will check if it downloaded
您可以“模拟”该函数以返回一个值,该值允许测试被测系统中的其余逻辑(在本例中是
download_csv
方法)。你知道吗假设我们有一个要求.txt像这样
使用这样的文件
test.py
,我们可以模拟decompress_csv
函数。你知道吗请注意,在正常情况下,您的测试代码可能位于与其测试的代码不同的文件中;这就是为什么我指出
module_that_contains_function_to_be_mocked
是关键的。你知道吗相关问题 更多 >
编程相关推荐