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

快云助手网站建设视频教程产品单页营销型网站模板

快云助手网站建设视频教程,产品单页营销型网站模板,网站建设合同书-详细版,关于做门户网站专栏内容通知规范 1、首先创建 py 文件命名以 test_ 开始或者以 _test 结尾 2、若是新建类,测试类需要以 Test_开头 3、测试用例(方法)需要以 test_开头 assert 断言 assert xx:判断 xx 为真 assert not xx:判断 xx 不为真 asse…

规范

1、首先创建 py 文件命名以 test_ 开始或者以 _test 结尾

2、若是新建类,测试类需要以 Test_开头

3、测试用例(方法)需要以 test_开头

assert 断言

assert xx:判断 xx 为真

assert not xx:判断 xx 不为真

assert a in b:判断 b 包含 a

assert a == b:判断 a 等于 b

assert a !=b:判断 a 不等于 b

from calculator import add, subtractdef test_add():   #passassert add(2, 3) == 5
def test_subtract():  #passassert subtract(5, 3) != 1def test_zhen():#failassert 0 
def test_zhen2():#passassert 1def test_jia():#passassert not 0 
def test_jia1():#failassert not 1def test_include():#passassert 1 in [1,2,3]
def test_include2():#failassert 4 in [1,2,3]

执行

命令行执行:

  • pytest .\test_calculator.py 指定执行某文件

  • pytest 文件夹下所有test_* 或者*_test的文件,全部执行

  • pytest test_tt.py::Test::test_case1 pytest路径/文件名::类名::方法名 执行指定文件指定方法

  • pytest test_tt.py::test_case1 pytest路径/文件名::方法名

ide执行:

if __name__ == '__main__':

- pytest.main(['test_tt.py']) 指定文件, 指定执行某文件

- pytest.mian() 没有指定文件,文件夹下所有test_* 或者*_test的文件,全部执行

- pytest.main(['test_tt.py::Test::test_case1']) 指定文件指定类指定方法

- pytest.main(['test_tt.py::test_case1']) 指定文件指定方法

命令行参数执行:

pytest -q 简化控制台的输出

        pytest -q test_calculator.py

pytest -v 输出用例更加详细的执行信息,比如用例所在文件和用例名称

        pytest -v test_calculator.py

pytest -k 执行用例中包含‘关键字’的用例 pytest -v -k "include" 方法名包含include的会被执行

        pytest -k "include" test_calculator.py

pytest -s 输出用例中的调试信息,比如 print 打印信息,如果不加参数则不输出打印信息

        pytest -s test_calculator.py

pytest -m 执行‘标记’的内容,执行特定的测试用例,执行有相同标记的测试用例

        标记方法:方法前 @pytest.mark.run_these 打标run_these

        执行 pytest -m run_these test_calculator.py test_calculator文件中的所有打标run_these的都会被执行

pytest -x执行失败则停止执行,后面的用例不会被执行

        pytest -x test_calculator.py 执行出fail就会break

pytest --maxfail=n执行失败 n 次之后停止执行,n 是执行失败的次数

        pytest --maxfail=3 test_calculator.py 执行,当fail3次的时候,break

pytest --count=n 执行用例 n 次,n=2 就是执行两次

        pytest --count=2 test_calculator.py 执行2次

pytest --lf (last failed)重新运行上次失败的用例,若没有失败的会全部跑

        pytest --lf test_calculator.py 将上次失败的again一遍,没有失败的就all again

pytest --ff (failed first)重新运行所有用例,但首先运行上次失败的用例

        pytest --ff test_calculator.py 所有全部执行一遍,上次失败的优先执行

标记跳过执行

skipif(condition, reason=None) 参数:

condition:跳过的条件,必传参数reason:标注原因,必传参数

使用方法:

@pytest.mark.skipif(condition, reason="xxx") condition 条件为真时跳过

@pytest.mark.skip()

标记预期失败

xfail(condition=None, reason=None, raises=None, run=True, strict=False)

常用参数:

condition:预期失败的条件,必传参数reason:失败的原因,必传参数

使用方法:

@pytest.mark.xfail(condition, reason="xx")condition 为真则标记失败

在某种条件不满足的时候, 预期它是失败的, 就将它标记为预期失败, 若condition 条件不满足则正常执行

预期失败:

  • 没有条件,失败就是xfailed

  • 有条件,条件满足为真,失败就是xfailed

  • 有条件,条件不满足为假,失败就是failed

参数化

方法:

parametrize(argnames, argvalues, indirect=False, ids=None, scope=None)

常用参数:

argnames:参数名

argvalues:参数对应值,类型必须为 list 当参数为一个时格式:[value]

当 参 数 个 数 大 于 一 个 时 , 格 式 为 : [(param_value1,param_value2.....),(param_value1,param_value2 )]

使用方法:

@pytest.mark.parametrize(argnames,argvalues) 参数名,参数值

@pytest.mark.parametrize("a",[3,6])单参数

@pytest.mark.parametrize("a,b",[(1,2),(0,3)])多参数

参数值为 N 个,测试方法就会运行 N 次

标记用例多次执行

首先安装 repeat: pip install pytest-repeat

@pytest.mark.repeat(n)执行当前用例 n 次 然后再往下执行其他用例

标记用例执行顺序

使用:

安 装 pip install pytest-ordering

@pytest.mark.run(order=1)---第1个执行

@pytest.mark.run(order=2)---第2个执行

@pytest.mark.last---最后执行

fixtrue

自定义测试用例预置条件--pytest 精髓fixture

@pytest.fixture()(scope="function",params=None,autouse=False, ids=None, name=None)

调用时被优先执行 预处理或者重复操作scope:被标记方法的作用域

function(default):作用于每个测试方法,每个 test 都运行一次

class:每个 class类执行开始时执行一次 @pytest.fixture()(scope="class",autouse=True)

module:每个 module 的所有 test开始前只执行一次 @pytest.fixture()(scope="module",autouse=True)

session:多个.py 文件的用例的时候, 如果多个用例只需调用一次fixture,那就可以设置为 scope="session"。

params:(list 类型)提供参数数据,供调用标记方法的函数使用

autouse:是否自动运行,默认为 False 不运行,设置为 True 自动运行

若不为 True 则需要调用才会优先执行。

@pytest.fixture()

定义函数,命名不要以 test 开头与用例区分开,fixture 有返回值, 没有返回值默认为 None。用例调用 fixture 返回值,直接就是把 fixture 的函数名称当做变量名称。

生成测试报告

想要生成测试报告,需要先安装 pytest-html

安装命令: pip install pytest-html

  • 命令行生成:pytest --html==路径/文件名.html 执行用例文件.py

    • pytest --html==./report_sample.html test_sample.py html报告

    • pytest --junit-xml==./report_sample.xml test_sample.py xml报告

  • 使用 PyCharm 生成报告

  • if name == "__main__": pytest.main('-s','-v','--html==./report_sample.html','test_samle.py')


文章转载自:

http://QUdp2NEY.xLmpj.cn
http://uLy1vMAT.xLmpj.cn
http://HqO5o9wU.xLmpj.cn
http://Fwu7aEpD.xLmpj.cn
http://5NdDAlmu.xLmpj.cn
http://58FzOzID.xLmpj.cn
http://EVXXUXLd.xLmpj.cn
http://czkDy69G.xLmpj.cn
http://L7zQTTLi.xLmpj.cn
http://u9CxqOqI.xLmpj.cn
http://2Zuo5KSI.xLmpj.cn
http://8xEAFSc7.xLmpj.cn
http://HnV1bxTk.xLmpj.cn
http://cY6hRd6k.xLmpj.cn
http://x0FmZ7cL.xLmpj.cn
http://0UjnUqIn.xLmpj.cn
http://xv0HYOKe.xLmpj.cn
http://ykX4qdDH.xLmpj.cn
http://J2YY81Zl.xLmpj.cn
http://UwzzsauT.xLmpj.cn
http://8roSWCK6.xLmpj.cn
http://99TPA6os.xLmpj.cn
http://nll4rJjS.xLmpj.cn
http://NC6TMMGC.xLmpj.cn
http://dI7K1kp0.xLmpj.cn
http://haCag9Zb.xLmpj.cn
http://Z7dgLWXm.xLmpj.cn
http://1Nu52DLd.xLmpj.cn
http://F5sUOhwK.xLmpj.cn
http://yh4vg9zW.xLmpj.cn
http://www.dtcms.com/wzjs/622164.html

相关文章:

  • 山东省德州禹城住房建设厅网站微信公众平台小程序二维码怎么生成
  • 网站建设整体方案2008 iis7添加网站
  • 怎样做3d动画短视频网站江苏优质网站制作公司
  • 专业网站开发联系方式品牌网站建设保障大蝌蚪
  • 广州做网站的价格wordpress仪表盘添加内容
  • 网站关键词如何做竞价汽车电子商务网站建设规划书
  • 能赚钱的网站怎么做网站建设国标行业分类
  • 网站审批私有云笔记 wordpress
  • 网站访问量排行榜wordpress 获取文章时间
  • 天津网站建设seo优化营销推广工作内容
  • 静态网站源文件下载wordpress入门使用
  • .net做网站的吗网站请人做的 域名自己注册的 知道网站后台 怎么挂自己的服务器
  • 创建网站建设邯郸免费发布信息平台
  • 万网 成品网站山东省住房城乡建设厅网站首页
  • 怎么搭建局域网网站河北中尊建设工程有限公司官方网站
  • 湖南网站建设小公司成交功能网站
  • 河南企业网站优化外包wordpress允许注册
  • 珠海电商网站建设网站dedecms数据库
  • 如何做家教网站赚钱中亿丰建设集团股份有限公司官方网站
  • 铜陵市建设工程管理局网站网络推广方法怎么样
  • 网站seo优化免费手机购物网站设计
  • 怎么做新网站才能被百度收录做微商进哪个网站安全
  • 广州从化网站建设dw5怎样做网站
  • 网站备案承若怎么写wordpress 插件 重置密码
  • 创建网站容易吗电商网站开发过程是什么
  • 什么网站做外链优化好华东建设安装有限公司网站
  • 湖南电子科技网站建设绍兴做网站服务
  • 龙岗坑梓网站建设wordpress 插件破解版
  • alexa全球网站排名什么是互联网公司
  • 阿里巴巴免费做网站吗wordpress客户端linux