我如何将测试结果作为参数发送到我的python脚本?



我创建了一个计划任务,我的cypress脚本每小时运行一次。但在那之后,我想执行一个python脚本并传递结果数据。

运行脚本并获取"结果";是成功还是失败

$ cypress run --spec "cypress/integration/myproject/myscript.js"

并传递"结果"。数据到python脚本

$ python test.py results

我该怎么做?

有一个能够运行外部命令的subprocess模块,示例如下:

import subprocess
def get_test_output():
    filepath = './cypress/integration/myproject/myscript.js'
    res = subprocess.run(
        ['echo', filepath],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
    )
    # In your case it will be:
    # res = subprocess.run(
    #     ['cypress', 'run', '--spec', filepath],
    #     stdout=subprocess.PIPE,
    #     stderr=subprocess.STDOUT,
    # )
    return res.stdout.decode()

if __name__ == '__main__':
    test_res = get_test_output()
    print(test_res)
    # => ./cypress/integration/myproject/myscript.js

您可以在test.py的开头运行cypress,并将结果进一步传递给所需的函数

最新更新