import time
import allure
import pytest
import os
# 1.pytest将在当前目录及其子目录中运行test _ * .py或* test.py形 式的所有文件。
# 2.以test_开头的函数,以Test开头的类,以test_开头的方法。所有包 package都要有__init_.py文件。
@allure.feature('我是主功能')
class TestCase():
def test_01(self):
print("测试数据")
assert 'h' in 'hello'
pass
# @pytest.mark.skip
@allure.story('我是子功能模块1')
def test_02(self):
print("跳过")
# @pytest.mark.xfail
@allure.story('我是子功能模块2')
def test_03(self):
print('定位为失败')
assert 1==1
@allure.step("我是一个大步骤")
def test_04(self):
with allure.step("我是一个小步骤的名字"):
time.sleep(5)
print("我会休眠5秒再执行")
@allure.severity(allure.severity_level.BLOCKER)
def test_05(self):
print("我是重要级别的测试方法-会堵塞的")
@allure.severity(allure.severity_level.TRIVIAL)
def test_06(self):
print('我是普通级别的测试方法')
print('执行我时,需要输入 pytest -s -v 文件名 --allure-severities normal,critical ')
def test_07(self):
print('我下面会添加一个网页')
allure.attach('<head></head><body>首页内容<body>','错误界面显示的内容',allure.attachment_type.HTML)
def test_08(self):
print('我会添加一个图片')
allure.attach.file('001.png',attachment_type=allure.attachment_type.PNG)
if __name__ == '__main__':
pytest.main(['-s','test_cs.py','--alluredir','temp/xml'])
# os.system('allure generate ./temp -o ./temp/hmtl --clean')
pytest+allure 使用记录
最新推荐文章于 2023-12-19 14:41:32 发布