jenkins+pytest+allure
作者:互联网
1. pytest测试代码
import pytest import allure class Test_ABC: @pytest.fixture() def before(self): print("------->before") yield print("------->after") @allure.feature("分类1") def test_a(self, before): # test_a方法传入了被fixture标识的函数,已变量的形式 print("------->test_a") assert 1 @allure.feature("分类1") def test_b(self): print("------->test_b") assert 1 @allure.feature("分类2") def test_c(self): print("------->test_c") assert 1 @allure.feature("分类2") @pytest.mark.parametrize(('x', 'y'), [(4, 4), (5, 5), (3, 3)]) def test_simple_assume(self, x, y): # 执行多个断言需要安装pytest-assume print("测试数据x=%s, y=%s" % (x, y)) pytest.assume(x == y) pytest.assume(x + y > 2) pytest.assume(x > 1) print("测试完成!") if __name__ == '__main__': pytest.main(['-s', 'test_demo.py', "--alluredir=report"])
2. jenkins配置
构建-执行shell命令
#!/bin/bash /usr/local/bin/pytest -s -q --alluredir=/Users/xxx/Documents/myjenkins/workspace/test_allure/report_test --clean-alluredir /Users/xxx/Documents/myresource/test/test_demo.py /usr/local/bin/allure generate --clean /Users/xxx/Documents/myjenkins/workspace/test_allure/report_test -o /Users/xxx/Documents/myjenkins/workspace/test_allure/report_test2
3. allure配置
需要安装Allure插件
标签:allure,assume,self,print,pytest,test,jenkins 来源: https://blog.51cto.com/zhzhgo/2561244