通过Dropbox交互测试代码

时间:2018-08-20 15:43:36

标签: python-3.x dropbox-api

我有一堆代码,它们定期从Dropbox下载文件。

def photos_list(dbx: Dropbox, folder: str, cursor: str = None, recursive: bool=False) -> Generator[FileMetadata, None, None]:
    has_more = True
    while has_more:
        if cursor is not None:
            files = dbx.files_list_folder_continue(cursor)
        else:
            files = dbx.files_list_folder(folder; recursive=recursive)

        for file in files.entries:
            if isinstance(file, FileMetadata):
                yield file
        cursor = files.cursor
        has_more = files.has_more

我正在使用unittest.TestCase类继承来测试我的代码。我可以与Dropbox进行尽可能多的交互,这样就可以在不调用Dropbox的情况下测试代码。但是我想测试像photos_list这样的函数,最好的方法是什么?用unittest.mock模拟投寄箱?我读过我应该使用pytest,但是看不到为什么我应该为pytest重写所有测试的明确观点。如果您对测试与api有关的python代码有任何阅读建议,那就太棒了。

0 个答案:

没有答案
相关问题