python - 如何在 Unittest 中使用多个失败并将它们打印为失败而不结束测试?
问题描述
我需要用几个程序来编写一个测试来检查几个用例(步骤)。对于每个步骤,它可能是一个子步骤。每个步骤/子步骤都在检查其他内容,例如:
Procedure 1 :
Step 1 : Verify something
Step 2 : Compare ....
Sub-step 2.1 : Compare ...
Sub-step 2.2 : Compare ...
Step 3 : Configure ....
每个步骤或子步骤都可能失败/通过,测试将正常继续。
Step 1 : Verify something - PASS
Step 2 : Compare .... - FAIL
Sub-step 2.1 : Compare ... - PASS
Sub-step 2.2 : Compare ... - FAIL
Step 3 : Configure .... - PASS
我还需要将结果逐步包含在交互式 HTML 结果文件中(我使用了 Allure),其中包含每个步骤的结果和信息。
我尝试使用 Pytest 和 Allure(用于交互式 HTML 结果报告文件),但为了表示失败,我需要使用 Assert,并且 Assert 异常会导致测试立即失败。
除了 Allure 之外,还有没有其他框架可以帮助我创建高层次的 HTML 报告文件并以 Assert 以外的其他方式表示失败?有没有办法让 Allure 在不使用 Assert 的情况下显示失败?
def test_procedure_1(self):
with allure.step("1. Configure "):
Assert 0
with allure.step("2. prints"):
Assert 1
with allure.step("3. attached"):
Assert 0
with allure.step("4. compare"):
Assert 1
其他例子:
def test_procedure_2(self):
with self.subTest("step 1:"):
Assert 0
with self.subTest("step 1.1:"):
Assert 1
with self.subTest("step 1.1.1:"):
Assert 1
with self.subTest("step 1.1.1.1:"):
Assert 0
with self.subTest("step 2:"):
Assert 1
解决方案
推荐阅读
- c - 使用 malloc 和 realloc 来使用 C 结构,但占用的内存空间是我计算的两倍
- c++ - 我们应该将向量声明为全局常量还是将其传递给递归函数以减少内存使用?
- python - 如何检查运行方法的状态
- javascript - Vuetify v-btn 点击事件
- javascript - Javascript onoff按钮在聊天机器人中不起作用
- android - firebase 在未知 uid 后从 uid 获取价值
- java - Jackson 动态数据反序列化失败,
- java - java.library.path 中没有 rxtxSerial
- cucumber - Cucumber\Rest Assured:如何获取请求规格?
- sparql - 如何在 dbpedia 中获取 owl:sameas