1. pytest測試代碼python
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
構建-執行shell命令bash
#!/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配置ide
須要安裝Allure插件函數