pytest第一节

时光怂恿深爱的人放手 提交于 2020-04-06 21:43:55

python鄙视链:pytest>uniitest>rebotframe>流水账>hello word

进了新公司,本来用unittest框架做自动化的,但是因为报告不美观,比不上allure,被老板要求要使用pytest框架。才知道原来还有这么一条鄙视链。

还有什么可说的呢?盘它

1.安装

pip install -U pytest 

 

pytest 运行规则:文件名和函数都以test_开头。测试类以Test开头,且不能有__init__方法。断言assert.

 

下载allurehttps://github.com/allure-framework/allure2/releases,把解压后的 bin 目录添加到环境变量的 PATH 中。

#test.py  #the content of test.pyimport pytestimport csv,ospath=os.getcwd()# print(path)datapath=path+"\config\config1.csv"# print(datapath)file=open(datapath,"r")table=csv.reader(file)for row in table:    if row[1]=="1":        print(row[0])        # pytest.main([row[0],"-s", "--html=test_result/"+row[2]])        pytest.main([row[0], "-s", "-q","--alluredir=test_result/xml"])

打开命令行,切换到项目下,执行  python test.py  ;   

allure generate test_result/xml -o test_result/html --clean
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!