在allure step函数中获取空列表值

2024-06-17 15:34:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经在名为takeScreenshot()的函数中将屏幕截图\u list定义为全局列表变量,并尝试在testResultPngToPdf()中访问相同的列表变量。当我打印屏幕截图的长度时,它不是空的。 在testResultPngToPdf()的诱惑步骤中,same无法访问。您能帮我确定确切的根本原因吗

takeScreenshot()的代码段:

global screenshots_list
screenshots_list = [] # Storing list of all screenshot captured  

@allure.step("Capture Screenshots")
def takeScreenshot(ind):
    '''function used to take screenshots for each event'''  
    logging.info(f"Screenshots captured!")
    filename = "temp/"+scenario_to_run+"_"+str(ind)+".png"
    driver.get_screenshot_as_file(filename)
    image = Image.open(filename)
    image = image.convert("RGB")
    screenshots_list.append(image)
    logging.info(f"inside take screenshot  sceenshotlist::::{len(screenshots_list)}")

testResultPngToPdf()的代码段:

@allure.title("Generating Test Results")
def testResultPngToPdf(result_type):
    '''Function call to make pdf for all screen shots taken during execution'''
    logging.info(f"Total Screenshots captured : {len(screenshots_list)}")
    logging.info(f"Result type value  : {result_type}")
    screenshots_list[-1] = pass_fail_watermark(result_type, screenshots_list[-1])
    pdf_filename = ("TestResults/"+scenario_to_run+"_" +current_time+"_"+result_type+".pdf")
    screenshots_list[0].save(pdf_filename, "PDF", resolution=100.0,
                        save_all=True, append_images=screenshots_list[1:])
    screenshots_list.clear()

Tags: toimageinfopdfloggingtyperesultall