我需要测试一个工作流,其中所有页面的顺序相同,但在测试时不知道用户从哪里开始。所有单独的页面都有带参数的独立功能。它们彼此独立运行,我希望保持这种状态
我以为我可以将所有函数存储在一个列表中,然后传递一个变量来指示从列表中的何处开始,但是当我定义列表时,它只是运行函数!有什么解决办法吗?
这是我在确定函数正在运行之前得到的信息
teststeps = [page1(param1, param2), page2(param1, param2), page3(param1, param2), page4(param1, param2
teststepnumber = determinepage(param1, param2)
for item in teststeps[teststepnumber:]:
**Incomplete because I couldn't figure out how to run the functions**
最佳答案
您只需将函数本身(而不是实际调用它们的结果)放在列表中,以便您可以在稍后的步骤中调用它们:
test_steps = [page1, page2, page3, page4]
test_step_number = determine_page(param1, param2)
for test_step in test_steps[test_step_number:]:
test_step(param1, param2)
关于python - 从列表中运行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63343804/