pytest使用总结

文件命名

必须以test_xxxx.py命名文件名

每一个测试用例要以test_xxx命令方法的名字

'''
def test_coure():
'''


image.png

.成功
F失败

跳过测试用例
@pytest.mark.skip(reason="input your skip reason")

'''

创建多个py文件是为了区分(分割)不同的类型的测是用例(不同类型的功能模块)

def test_sy():
shouye = ("text","首页")
sygh = ("text","生涯规划")
sykt = ("text","生涯课堂")
kc_id = ("id","com.znb.zxx:id/tv_title") # 生涯课堂中课程
find_element(driver,shouye).click()
find_element(driver,sygh).click()
# find_element(driver,sykt).click()
try:
assert is_element_exist(driver,sykt) == True
print("进入生涯首页成功")
except:
print("进入生涯首页失败")
find_element(driver,sykt).click()
try:
assert is_element_exist(driver,kc_id) == True
print("生涯课程执行成功")
except:
print("生涯课程执行失败")

def test_course_details():
kc_id = ("id","com.znb.zxx:id/tv_title")
mf_course = ("text","免费领取")
find_element(driver,kc_id).click()
find_element(driver,mf_course).click()
try:
assert is_element_exist(driver,mf_course) == False
print("领取免费课程成功")
except:
print("没找到免费课程按钮")
'''

Allure测试报告

1安装并配置allure环境变量
2安装allure-pytest插件
3 执行测试脚本,并生成测试结果pytest ./ --alluredir=result
4 把测试结果编译成网页测试报告 allure generate result –o report --clean
5 打开测试报告 allure open -h 127.0.0.1 -p 10866 report


image.png

用法:
pytest test_demo.py --alluredir ./result
conftest.py 文件名是固定的 在里面写入的方法 其他文件调用的时候不需要from XXX import xxx

import pytest


@pytest.mark.parametrize("arg_1,arg_2,arg_3", [(4399,4000,399),(2011,2000,11)])
def test_add_by_func_aaa(arg_1,arg_2,arg_3):
    assert  arg_1 == arg_2 + arg_3


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。