如何在测试完成后以编程方式获取Pytest测试结果

2024-10-01 13:27:02 发布

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

enter image description here 我正在使用Zalenium在docker中运行Pytest测试。Zalenium仪表板需要与pytest进行某种通信才能获得结果。目前,Zalenium仪表板只将结果报告为“已完成”,而不是“成功”或“失败”。我不知道如何从pytest获得通过或失败的结果,甚至不知道在哪里放置Zalenium钩子的代码。Zalenium的文档中有一个很好的例子,但它是针对Java和testNG的。你知道吗

By default, tests in Zalenium are marked in the dashboard either as COMPLETED (session finishes normally) or TIMEOUT (session was ended due to inactivity). You can mark the test as passed or failed based on the assertions you do on your side with your test framework, add a cookie from with the name zaleniumTestPassed with a value of true (if the test passes) or false (if the test fails). This could be done in the after method where you already know if the test passed or failed. Here is an example in Java:

Cookie cookie = new Cookie("zaleniumTestPassed", "true");
    webDriver.manage().addCookie(cookie);

Tags: ortheintestifpytestcookiesession