我有一个读取 excel 文件并根据其内容生成报告的功能。如何在 pytest 中编写测试以检查文件是否生成并按预期创建报告?
import openpyxl
def create_report(file_path):
#open an existing report
xfile = openpyxl.load_workbook(file_path)
sheet = xfile.get_sheet_by_name('Sheet1')
sheet['A1'] = 'hello world'
sheet['A3'] = 22
sheet.cell(row=2, column=2).value = 2
#Write data to excel sheet
#save as new report
xfile.save('test_report.xlsx')
测试涉及创建新文件以生成报告的功能时,最佳实践是什么?这个功能可以通过Mocking文件路径来测试吗?