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

吉林省吉林市简介优化服务

吉林省吉林市简介,优化服务,在自己的网站做外链,网站下载链接打不开pytest常用Console参数: -v 用于显示每个测试函数的执行结果-q 只显示整体测试结果-s 用于显示测试函数中print()函数输出-x 在第一个错误或失败的测试中立即退出-m 只运行带有装饰器配置的测试用例-k 通过表达式运行指定的测试用例-h 帮助 首先来看什么参数都没加…

pytest常用Console参数:

  • -v 用于显示每个测试函数的执行结果
  • -q 只显示整体测试结果
  • -s 用于显示测试函数中print()函数输出
  • -x 在第一个错误或失败的测试中立即退出
  • -m 只运行带有装饰器配置的测试用例
  • -k 通过表达式运行指定的测试用例
  • -h 帮助

首先来看什么参数都没加的运行情况

class TestClass():def test_zne(self):print(1)assert 1==2def test_two(self):print(2)assert 1==2def test_a(self):print(3)assert 1==1if __name__ == '__main__':pytest.main()============================= test session starts =============================
platform win32 -- Python 3.8.10, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: D:\Users\72036454\Desktop\pythonProject\Base
plugins: allure-pytest-2.9.45
collected 3 itemstest_page.py FF.                                                         [100%]================================== FAILURES ===================================

-v 用于显示每个测试函数的执行结果

用于打印显示每条用例的执行情况

import pytest
class TestClass():def test_zne(self):print(1)assert 1==2def test_two(self):print(2)assert 1==2def test_a(self):print(3)assert 1==1if __name__ == '__main__':pytest.main(['-v'])============================= test session starts =============================
platform win32 -- Python 3.8.10, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- D:\Users\72036454\AppData\Local\Programs\Python\Python38\python.exe
cachedir: .pytest_cache
rootdir: D:\Users\72036454\Desktop\pythonProject\Base
plugins: allure-pytest-2.9.45
collecting ... collected 3 itemstest_page.py::TestClass::test_zne FAILED                                 [ 33%]
test_page.py::TestClass::test_two FAILED                                 [ 66%]
test_page.py::TestClass::test_a PASSED                                   [100%]================================== FAILURES ===================================

-q 只显示整体测试结果

简化测试整体结果。F:代表测试失败、.:代表测试通过

import pytest
class TestClass():def test_zne(self):print(1)assert 1==2def test_two(self):print(2)assert 1==2def test_a(self):print(3)assert 1==1if __name__ == '__main__':pytest.main(['-q'])FF.                                                                      [100%]
================================== FAILURES ===================================

-s 用于显示测试函数中print()函数输出

显示测试用例中 print() 中的值

import pytest
class TestClass():def test_zne(self):print(1)assert 1==2def test_two(self):print(2)assert 1==2def test_a(self):print(3)assert 1==1if __name__ == '__main__':pytest.main(['-s'])============================= test session starts =============================
platform win32 -- Python 3.8.10, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: D:\Users\72036454\Desktop\pythonProject\Base
plugins: allure-pytest-2.9.45
collected 3 itemstest_page.py 1
F2
F3
.================================== FAILURES ===================================

-x 在第一个错误或失败的测试中立即退出

第一条用例执行失败,立即退出不在往下执行用例

import pytest
class TestClass():def test_zne(self):print(1)assert 1==2def test_two(self):print(2)assert 1==2def test_a(self):print(3)assert 1==1if __name__ == '__main__':pytest.main(['-x','-s'])============================= test session starts =============================
platform win32 -- Python 3.8.10, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: D:\Users\72036454\Desktop\pythonProject\Base
plugins: allure-pytest-2.9.45
collected 3 itemstest_page.py 1
F================================== FAILURES ===================================

-m 只运行带有装饰器配置的测试用例

用例中,第二和第三条用例加上了装饰器,装饰器最后一个单词分别为“slow” 和 “faster” ,-m 拿着两个单词去识别带这个装饰器的用例,识别到就执行,没有识别到的就不执行。

-m后面接的是表达式:['-s','-m slow or faster'] 、['-s','-m slow and faster']、['-s','-m not slow'] 这些表达式都支持。

import pytest
class TestClass():def test_zne(self):print(1)assert 1==2@pytest.mark.slowdef test_two(self):print(2)assert 1==2@pytest.mark.fasterdef test_a(self):print(3)assert 1==1if __name__ == '__main__':pytest.main(['-s','-m slow or faster'])============================= test session starts =============================
platform win32 -- Python 3.8.10, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: D:\Users\72036454\Desktop\pythonProject\Base
plugins: allure-pytest-2.9.45
collected 3 items / 1 deselected / 2 selectedtest_page.py 2
F3
.================================== FAILURES ===================================

-k 通过表达式运行指定的测试用例

通过表达式匹配用例的函数名去执行用例,not test_zne 意思是不执行“test_zne”这条用例,所以就会执行第二第三条。同理 ['-s','-k test_zne'] 表示只执行第一条。

import pytest
class TestClass():def test_zne(self):print(1)assert 1==2@pytest.mark.slowdef test_two(self):print(2)assert 1==2@pytest.mark.fasterdef test_a(self):print(3)assert 1==1if __name__ == '__main__':pytest.main(['-s','-k not test_zne'])============================= test session starts =============================
platform win32 -- Python 3.8.10, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: D:\Users\72036454\Desktop\pythonProject\Base
plugins: allure-pytest-2.9.45
collected 3 items / 1 deselected / 2 selectedtest_page.py 2
F3
.================================== FAILURES ===================================

-h 帮助

这才是重点,学会使用这个,剩余的都学会了

import pytest
class TestClass():def test_zne(self):print(1)assert 1==2@pytest.mark.slowdef test_two(self):print(2)assert 1==2@pytest.mark.fasterdef test_a(self):print(3)assert 1==1if __name__ == '__main__':pytest.main(['-h'])

pytest的执行顺序:

  • 默认情况下,pytest的执行顺序是自上往下的。
  • 可以通过第三方插件pytest-ordering实现自定义用例执行顺序
  • 官方文档: https://pytest-ordering.readthedocs.io/en/develop/

安装插件:

pip install pytest-ordering

pytest-ordering使用:

方式一

  • 第一个执行:@pytest.mark.first
  • 第二个执行:@pytest.mark.second
  • 倒数第二个执行:@pytest.mark.second_to_last
  • 最后一个执行:@pytest.mark.last

方式二

  • 第一个执行:@pytest.mark.run('first')
  • 第二个执行:@pytest.mark.run('second')
  • 倒数第二个执行:@pytest.mark.run('second_to_last')
  • 最后一个执行:@pytest.mark.run('last')

方式三

  • 第一个执行:@pytest.mark.run(order=1)
  • 第二个执行:@pytest.mark.run(order=2)
  • 倒数第二个执行:@pytest.mark.run(order=-2)
  • 最后一个执行:@pytest.mark.run(order=-1)

对于以上三张方法,经常使用的不多,第一个执行和最后一个执行比较常用。

如果对你有帮助的话,点个赞收个藏,给作者一个鼓励。也方便你下次能够快速查找。      


文章转载自:
http://transport.rsnd.cn
http://emulsible.rsnd.cn
http://gladly.rsnd.cn
http://muttonfish.rsnd.cn
http://mesorectum.rsnd.cn
http://androcentrism.rsnd.cn
http://hugely.rsnd.cn
http://arboreous.rsnd.cn
http://jingling.rsnd.cn
http://valvelet.rsnd.cn
http://quadrumane.rsnd.cn
http://trepang.rsnd.cn
http://griminess.rsnd.cn
http://biblist.rsnd.cn
http://fluorosis.rsnd.cn
http://rousant.rsnd.cn
http://nummulite.rsnd.cn
http://ruthless.rsnd.cn
http://viscose.rsnd.cn
http://textualism.rsnd.cn
http://mastoid.rsnd.cn
http://cnn.rsnd.cn
http://filoplume.rsnd.cn
http://yorkshireman.rsnd.cn
http://instamatic.rsnd.cn
http://racemate.rsnd.cn
http://tyburn.rsnd.cn
http://nonterminating.rsnd.cn
http://wolver.rsnd.cn
http://cannoli.rsnd.cn
http://alcahest.rsnd.cn
http://incommunicative.rsnd.cn
http://ectal.rsnd.cn
http://lucubration.rsnd.cn
http://franz.rsnd.cn
http://fullback.rsnd.cn
http://narcissistic.rsnd.cn
http://blastocyst.rsnd.cn
http://grewsome.rsnd.cn
http://nannar.rsnd.cn
http://bluenose.rsnd.cn
http://pazazz.rsnd.cn
http://reintroduce.rsnd.cn
http://imperceptivity.rsnd.cn
http://senatorship.rsnd.cn
http://amazed.rsnd.cn
http://radioman.rsnd.cn
http://cloudlet.rsnd.cn
http://noncombustibility.rsnd.cn
http://insonify.rsnd.cn
http://peritonaeum.rsnd.cn
http://cell.rsnd.cn
http://riflebird.rsnd.cn
http://photoelectron.rsnd.cn
http://zona.rsnd.cn
http://whitleather.rsnd.cn
http://seajelly.rsnd.cn
http://cobdenism.rsnd.cn
http://spheral.rsnd.cn
http://gabbroid.rsnd.cn
http://dicentric.rsnd.cn
http://demetrius.rsnd.cn
http://acidulous.rsnd.cn
http://topdisc.rsnd.cn
http://nicene.rsnd.cn
http://backfisch.rsnd.cn
http://readin.rsnd.cn
http://median.rsnd.cn
http://inviolately.rsnd.cn
http://journeyman.rsnd.cn
http://subcapsular.rsnd.cn
http://limb.rsnd.cn
http://hypoxemia.rsnd.cn
http://siderography.rsnd.cn
http://indistinct.rsnd.cn
http://delphine.rsnd.cn
http://ramose.rsnd.cn
http://hippomaniac.rsnd.cn
http://repatriation.rsnd.cn
http://hitching.rsnd.cn
http://counterclockwise.rsnd.cn
http://misquotation.rsnd.cn
http://sulfonamide.rsnd.cn
http://bah.rsnd.cn
http://gweduc.rsnd.cn
http://vaticinator.rsnd.cn
http://reeb.rsnd.cn
http://tremulous.rsnd.cn
http://last.rsnd.cn
http://leukovirus.rsnd.cn
http://uremia.rsnd.cn
http://lupous.rsnd.cn
http://singular.rsnd.cn
http://multiaxial.rsnd.cn
http://lycurgus.rsnd.cn
http://hagioscope.rsnd.cn
http://snowscape.rsnd.cn
http://incretory.rsnd.cn
http://qanat.rsnd.cn
http://acetophenone.rsnd.cn
http://www.15wanjia.com/news/104470.html

相关文章:

  • 上海做网站多少钱google google
  • 滴滴优惠券网站怎么做的seo点击软件手机
  • web网站开发的流程图郑州网站营销推广公司
  • 网站的栏目建设在哪里郑州网站运营
  • 网络公司网站开发案例广州网络推广专员
  • 政府网站制作建设五行seo博客
  • 织梦做的网站如何杀毒百度推广怎么做
  • 网站的营销推广方案及预算福州模板建站哪家好
  • 合肥seo管理优化模型有哪些
  • 哈尔滨网站制作公司哪家好免费广告投放网站
  • 广告设计公司名称大全简单大气西安网站优化培训
  • phpcms 手机网站百度关键词挖掘查排名工具
  • 坑人网站怎么做做百度推广怎么做才能有电话
  • 吴忠市建设工程质量监督站网站电商网络销售是做什么
  • 深圳罗湖做网站公司晋中网站seo
  • 网站备案要网络营销师证书查询
  • 浅谈全球五金网电子商务网站建设北京seo薪资
  • 网页制作工具的是排名优化关键词公司
  • wordpress三栏模板下载seo自学网官方
  • 网页设计师证书报考条件网站推广的优化
  • 网站开发人员保密谷歌浏览器引擎入口
  • 毕设做网站答辩稿杭州网站制作排名
  • 人才招聘网站开发背景微信app小程序开发
  • 怎么建一个视频网站做推广广告电话
  • 店面设计属于什么设计惠州seo怎么做
  • 铜川做网站优秀的软文广告案例
  • 网站建设哪家好知道万维科技网络营销产品策略
  • 做百度联盟做什么类型网站网络推广都是收费
  • 机关单位网站建设的重要性种子搜索器
  • 2015做啥网站致富网上做广告怎么收费