1、準(zhǔn)備工作
安裝
pytest
pip install pytest
安裝
allure-pytest
pip install allure-pytest
安裝
allure
下載地址https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/,選擇相應(yīng)版本進行下載,解壓后配置環(huán)境變量
2、開始使用
test_01.py
import pytest
import os
def func_1(a, b):
return a + b
class TestClass:
def setup_class(self):
print("setup class start ......")
def setup(self):
print("setup start ......")
def test_001(self):
r = func_1(1, 2)
assert r == 3
def test_002(self):
r = func_1(2, 2)
assert r == 3
def test_003(self):
r = func_1(3, 2)
assert r == 3
def teardown(self):
print("tear down ......")
if __name__ == "__main__":
pytest.main(["--alluredir", "./report/result", "test_01.py"])
os.system("allure generate ./report/result -o ./report/html --clean")
運行即可