当前位置: 首页 > news >正文

网站建设 报价单 docasp网站建设案例

网站建设 报价单 doc,asp网站建设案例,搭建方案,网址提交收录一、Python测试框架,主要特点有以下几点: 简单灵活,容易上手;支持参数化;能够支持简单的单元测试和复杂的功能测试,还可以用来做selenium/appnium等自动化测试、接口自动化测试(pytestrequests…

一、Python测试框架,主要特点有以下几点:

  • 简单灵活,容易上手;
  • 支持参数化;
  • 能够支持简单的单元测试和复杂的功能测试,还可以用来做selenium/appnium等自动化测试、接口自动化测试(pytest+requests);
  • pytest具有很多第三方插件,并且可以自定义扩展,比较好用的如pytest-selenium(集成selenium)、pytest-html(html测试报告生成)、pytest-rerunfailures(失败case重复执行)、pytest-xdist(多CPU分发)、allure-pytest(生成测试报告)等;
  • 测试用例的skip和xfail处理;
  • 可以很好的和jenkins集成;
  • pytest默认执行顺序是按照case顺序位置先后执行的;
  • pytest.ini和conftest.py文件要放在执行的同级目录(根目录)

二、安装pytest

1、命令行安装:pip install pytest

2、通过pycharm 【File】-【settings】-【Python Interpreter】搜索后安装; 

通过命令行pytest执行test_mod1.py文件中的代码

import pytestdef test_one():print("执行测试用例test_one")def test_second():print("执行测试用例test_second")
在pycharm命令行中输入:pytest -v test_mod1.py
输出:
collected 2 itemstest_mod1.py::test_one PASSED                                                                                                                                                       [ 50%]
test_mod1.py::test_second PASSED

通过pytest.main( )执行test_mod1.py的代码

import pytestdef test_one():print("执行测试用例test_one")def test_second():print("执行测试用例test_second")if __name__ == '__main__':pytest.main(['-vs'])结果:
collecting ... collected 2 itemstest_mod1.py::test_one PASSED                                            [ 50%]执行测试用例test_onetest_mod1.py::test_second PASSED                                         [100%]执行测试用例test_second

三、识别case的规则

  • 如果pytest命令行有指定目录,则从该目录中开始查找测试用例文件,如果没有指定,则从当前运行目录开始查找文件。注意,该查找是递归查找,子目录中的文件也会被查找到。
  • 并不是能够查找到目录下的所有文件,只有符合命名规则的文件才会被查找。默认规则是以test_开头或者以_test结尾的.py文件。
  • 在测试文件中查找Test开头的类,以及类中以test_开头的方法,查找测试文件中test_开头的函数

文件目录结构如下

在命令行中执行 pytest -vs

D:\Python Data\pythonTeach>pytest -vs
# test_mod3.py
import pytestclass TestMod3:def test_five(self):print("执行测试用例test_five")def test_six(self):print("执行测试用例test_six")
# mod2_test.py
import pytestdef test_three():print("执行测试用例test_three")def test_four():print("执行测试用例test_four")
# test_mod1.py
import pytestdef test_one():print("执行测试用例test_one")def test_second():print("执行测试用例test_second")if __name__ == '__main__':pass

执行结果

mod2_test.py::test_three 执行测试用例test_three
PASSED
mod2_test.py::test_four 执行测试用例test_four
PASSED
test_mod1.py::test_one 执行测试用例test_one
PASSED
test_mod1.py::test_second 执行测试用例test_second
PASSED
mod3/test_mod3.py::TestMod3::test_five 执行测试用例test_five
PASSED
mod3/test_mod3.py::TestMod3::test_six 执行测试用例test_six
PASSED

因为 pytest -vs 该命令没有指定目录,则从 D:\Python Data\pythonTeach 文件夹(运行目录)递归查找以test_开头或者以_test结尾的.py文件,在测试文件中查找Test开头的类,以及类中以test_开头的方法,查找测试文件中test_开头的函数;

pytest 执行指定文件夹

pytest -vs ./mod3/结果:
collected 2 itemsmod3/test_mod3.py::TestMod3::test_five 执行测试用例test_five
PASSED
mod3/test_mod3.py::TestMod3::test_six 执行测试用例test_six
PASSED

递归执行mod3文件夹下的所有以test_开头或者以_test结尾的.py文件,在测试文件中查找Test开头的类,以及类中以test_开头的方法,查找测试文件中test_开头的函数;

三、pytest 执行case时可选参数

-v:                                        #打印详细运行的日志信息
-s:     pytest -s xxx.py                   #输出case中print的内容
-m:    pytest -m “tag名称”         #运行指定tag名称的用例,也就是运行有@pytest.mark.[标记名]这个标记的case
-k:     # pytest -k “类名、方法名、类名 and not 方法名” 运行指定case的用例
-x:          #遇到失败的case就是停止执行
--lf:       #只重新运行上次运行失败的用例(或如果没有失败的话会全部跑)
--ff:       #运行所有测试,但首先运行上次运行失败的测试(这可能会重新测试,从而导致重复的fixture setup/teardown)
--maxfail=num:   #当用例失败个数达到num时,停止运行
--collect-only:   #收集测试用例,展示出哪些用例会被执行(只是展示不会执行case)
--junit-xml:--junit-xml=path/name.xml        #在指定目录或当前目录下生成xml格式的报告(需要在pytest.ini文件内声明格式:junit_family=xunit2)
--steup-show                                #完整展示每个用例的fixture调用顺序
命令行执行:
pytest test_quick_start.py --junit-xml=report.xmlmain执行:
pytest.main(["-s", "TestCalc.py", "-m", "div", "--junit-xml=report.xml"])
pytest.main(["-vsx", "TestCalc.py", "-m", "div"])

@pytest.mark.标记名 为测试用例指定 tag 名称

import pytestdef test_one():print("执行测试用例test_one")@pytest.mark.smoke   # 为test_second()测试用例指定名称为smoke的tag
def test_second():print("执行测试用例test_second")
D:\Python Data\pythonTeach>pytest -vsm "smoke"

通过 -m "标记名" 指定执行用例 

结果:
test_mod1.py::test_second 执行测试用例test_second
PASSED

通过pytest.main( )执行标记的用例

# run_test.py
import pytestif __name__ == '__main__':pytest.main(["-vsm"," smoke","test_mod1.py"])

通过-k指定测试用例执行

D:\Buyer_test_code\testteach>pytest -vs -k "test_three"

执行结果

mod2_test.py::test_three 执行测试用例test_three
PASSED

上述命令行中加入了-k参数,-k “类名、方法名、类名 and not 方法名”来运行指定的case

任务:

1、编写test_demo1.py文件,文件中包含test_01, test_02,test_03函数,通过命令行执行test_demo1.py中的所有test开头的函数;

2、在项目目录下新建一个demo的文件夹,demo文件夹下新建test_demo2.py,test_demo2.py下包含test_04,test05函数,通过命令行执行该项目目录下所有test开头的.py文件;通过命令行只执行demo文件夹下的test开头的.py文件;

3、在命令行中分别加入-v, -s, -k 参数来执行case

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

http://www.yayakq.cn/news/674947/

相关文章:

  • 重庆网站推广专家网站建设在学校中的作用
  • 公司网站域名注册费用潍坊网站制作保定公司电话
  • 网站js修改头像代码怎么做各大视频网站的会员代理
  • 洛阳市App网站开发公司网站开发有哪些公司
  • 台州集团网站建设谷歌流量代理代理
  • 深圳的互联网公司排名郑州seo外包顾问热狗
  • 建筑人才网官方网站中国建筑科学院有限公司认证中心广东做网站哪家公司好
  • 设计模板网站不用付费就可以看亏亏的app
  • 贵阳网站建设服务公司网站建设评估体系
  • 做网站的费用如何入账东营信息网招聘信息
  • 昌江县住房和城乡建设局网站管理咨询合同
  • 哈尔滨网站建设模板策划泊头做网站价格
  • 制作一个网站费用logo设计公司北京
  • 如何构建网站平台做外贸在哪个网站比较好
  • 免费asp企业网站源码福建seo网站
  • 购物网站建设的意义与目的怎么免费做自己的网站
  • 宝安公司免费网站建设免费全能网站空间
  • 哈尔滨网站域名备案网站如何备案 流程图
  • 做app和做网站那个难娄底网站建设报价
  • 韩都衣舍网站建设的改进青岛做教育的网站
  • 开封做网站wordpress 修改时间
  • dede后台网站主页佛山seo优化电话
  • 网站建设技术服务合同wordpress能做出
  • 磐石网站建设仿糗事百科网站源码dede二次开发分享+评论+互动
  • 腾讯有做淘宝客网站吗河南建设工程信息网 就上平台中项网
  • 网站开发的几个步骤京东网的公司全称是
  • 重庆做网站 熊掌号企业建设网
  • wordpress网站建小程序成都商城网站建设地址
  • 芜湖做网站建设公司wordpress锚点定位
  • 如何利用织梦cms做企业网站手机网站导航菜单