I have a function that reads an excel file and generates a report based on its content. How do I write a test in pytest to check if the file is generated and the report is created as expected?
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')
What is the best practice when testing functions that involves creating a new file for generating a report? Can this function be tested by Mocking the file path?