import pytest # 被调用的函数 def abb(): with open("./data.txt", "r") as f: if "2" in f.read(): return True else: return False # 测试类 class Test_TG: def test_a(self): print("...test_a") assert True # 根据特定的条件,不执行标识的测试函数 @pytest.mark.skipif(abb(), reason="跳过此步骤...") def test_b(self): print("test_b") assert False # 标记测试函数为失败函数 @pytest.mark.xfail(abb(), reason="失败不执行...") def test_c(self): print("test_c") assert False def re_data_list(): list_data = [] with open("./data.txt", "r") as f: for i in f.readlines(): data = eval(i.split("=")[-1]) list_data.append(data) return list_data # 函数数据参数化 class Test_para: @pytest.mark.parametrize("a,b", re_data_list()) def test_a(self, a, b): print("a:%s,b:%s" % (a, b)) if __name__ == "__main__": pytest.main(["-s", "test_12.py", "--html=../report/report.html"])