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

男女做网站WordPress设置作者信息

男女做网站,WordPress设置作者信息,四川南充房产信息网,网页网页设计班pytest的fixture中文介绍可参考#xff08;不过文档稍微有点老#xff09;#xff1a; https://www.osgeo.cn/pytest/fixture.html#what-fixtures-are pytest各个作用域的fixture scope “function” 可作用于每个用例 fixture使用的声明放在类定义前面#xff0c;类中的…pytest的fixture中文介绍可参考不过文档稍微有点老 https://www.osgeo.cn/pytest/fixture.html#what-fixtures-are pytest各个作用域的fixture scope “function” 可作用于每个用例 fixture使用的声明放在类定义前面类中的每个用例执行时都会调用fixture装饰函数 fixture使用的声明放在用例前用例执行时会调用fixture装饰函数scope “class” 作用于整个类 fixture使用的声明放在类定义前面类中的第一个用例执行时会调用fixture装饰函数一次 fixture使用的声明放在类中的用例前用例执行时会调用fixture装饰函数一次之后的用例即时有pytest.mark.usefixtures(“fixture_class”)也不会执行scope “module” 作用于整个python文件 在整个python文件中只会调用一次 不管pytest.mark.usefixtures(“fixture_module”)声明放在哪里类外的用例前、类的声明前或这个类中的用例前fixture函数都只会在整个python文件执行第一个用例时调用一次scope “session” 作用于整个会话通常可以放在conftest.py文件中作为全局使用的前、后置步骤 在所有地方都可以使用pytest.mark.usefixtures(“fixture_session”) 例 import pytestpytest.fixture(scopefunction) def fixture_function():print(fixture_function ####)pytest.fixture(scopeclass) def fixture_class():print(fixture_class ----)pytest.fixture(scopemodule) def fixture_module(): print(fixture_module )def test_0():print(test_0)pytest.mark.usefixtures(fixture_class) pytest.mark.usefixtures(fixture_function) class Test_class():pytest.mark.usefixtures(fixture_module)def test_1(self):print(test_1)def test_2(self):print(test_2)def test_3(self):print(test_3)def test_4(self):print(test_4)打印内容如下 4 passed in 0.23s fixture_module fixture_class ---- fixture_function #### PASSED [ 25%]test_1 fixture_function #### PASSED [ 50%]test_2 fixture_function #### PASSED [ 75%]test_3 fixture_function #### PASSED [100%]test_4Process finished with exit code 01.2.pytest添加fixture装饰实现前置、后置方法 可以通过fixture夹具实现前置后置方法后置需要使用yeild来实现。 如果一个方法或者一个类想要同时调用多个fixture。有两种方法 可以使用pytest.mark.usefixtures()进行叠加。 注意叠加顺序先执行的后添加pytest.mark.usefixtures语句后执行的先添加。 需注意与直接传入fixture不同的是pytest.mark.usefixtures无法获取到被fixture装饰的函数的返回值 pytest.mark.usefixtures的使用场景是被测试函数需要多个fixture做前后置工作时使用可以在方法中添加多个fixture函数名作为入参执行顺序先入参的后调用。 具体如下 import pytestclass Test_hhh:pytest.fixturedef setup_step1(self):print(setup_step1 )pytest.fixturedef setup_and_teardown_step2(self):print(setup_step2 ####)yieldprint(teardown_setp2 ####\n)pytest.mark.usefixtures(setup_step1)def test_1(self):print(test_1)pytest.mark.usefixtures(setup_step1)pytest.mark.usefixtures(setup_and_teardown_step2)def test_2(self):print(test_2)def test_3(self, setup_step1, setup_and_teardown_step2):print(test_3)def test_4(self, setup_and_teardown_step2):print(test_4)setup_step1()、setup_and_teardown_step2()两个函数前添加了 pytest.fixture 装饰scope默认是function。 每次执行test_1用例之前都会先调用setup_step1()。 每次执行test_2用例之前都会先调用setup_and_teardown_step2()再调用setup_step1()。 每次调用test_3用例之前都会先调用setup_and_teardown_step2()再调用setup_step1()。 每次调用test_4用例之前都会先调用setup_and_teardown_step2()。 打印顺序如下 4 passed in 0.21s setup_step1 PASSED [ 25%]test_1 setup_step2 #### setup_step1 PASSED [ 50%]test_2 teardown_setp2 ####setup_step1 setup_step2 #### PASSED [ 75%]test_3 teardown_setp2 ####setup_step2 #### PASSED [100%]test_4 teardown_setp2 ####Process finished with exit code 0pytest中各个级别的setup和teardown方法 除了使用fixture来实现前置、后置。pytest也可以直接使用setup和teardown方案实现前置、后置。pytest的前置、后置分为方法级、类级和模块级。 方法级setup_method() teardown_method()类级别setup_class() teardown_class()模块级setup_module() teardown_method() def setup_module():print(setup_module)def teardown_module():print(teardown_module)def test_1():print(test_1)assert 1 1class Test_learn:def setup_method(self):print(setup_method)def teardown_method(self):print(teardown_method)def setup_class(self):print(setup_class)def teardown_class(self):print(teardown_class)def test_2(self):print(test_2)assert Truedef test_3(self):print(test_3)在整个文件中的第一个用例执行前setup_module()会被调用。 在整个文件中的最后一个用例执行后teardown_module()会被调用。 在类中的第一个用例执行前setup_calss()会被调用。 在类中的最后一个用例执行后teardown_class()会被调用。 在类中的每个用例执行前setup_method()会被调用。 在类中的每个用例执行后teardown_method()会被调用。 打印结果如下 test session starts collecting ... collected 3 itemstest_file.py::test_1 setup_module test_1 PASSED test_file.py::Test_learn::test_2 setup_classsetup_method test_2 PASSEDteardown_methodtest_file.py::Test_learn::test_3 setup_method test_3 PASSEDteardown_method teardown_class teardown_module 3 passed in 0.04s pytest参数化 可以使用pytest.mark.parametrize进行参数化具体用法如下 import pytestclass Test_learn:test_data [[正常登录, user1, password1, 登录成功],[密码错误, user2, password2, 用户名或密码错误请重新输入]]ids [i[0] for i in test_data]pytest.mark.parametrize(case, username, password, expect_text, test_data, idsids)def test_1(self, case, username, password, expect_text):print(\n,case,username, password, expect_text)assert Truedata2 [{username: 张三, password:123456},{username: 李四, password: 123456}]pytest.mark.parametrize(dic,data2)def test_2(self, dic):print(\n,dic[username], dic[password])assert Truepytest.mark.parametrize()中第一个参数参数名可以是一个或多个第二个参数test_data为具体数据第三个参数ids为用例名参数名和数组中元素按顺序对应取值。 如上第一个用例中数据有两条。第一条参数case‘登录成功’,username‘user1’, password‘password1’, expect_text‘登录成功’第一条用例的名称登录成功’。 参数的数据也可以是字典、元组等。 执行打印如下 test session starts collecting ... collected 4 itemstest_file.py::Test_learn::test_1[\u6b63\u5e38\u767b\u5f55] 正常登录 user1 password1 登录成功 PASSED test_file.py::Test_learn::test_1[\u5bc6\u7801\u9519\u8bef] 密码错误 user2 password2 用户名或密码错误请重新输入 PASSED test_file.py::Test_learn::test_2[dic0] 张三 123456 PASSED test_file.py::Test_learn::test_2[dic1] 李四 123456 PASSED 4 passed in 0.04s pytest跳过用例 无条件跳过用例 pytest.mark.skip条件成立时跳过用例 pytest.mark.skipif(表达式, reason‘跳过用例的原因’) 如 import pytest# 会被跳过的 pytest.mark.skipif(4%2 0, reason跳过用例的原因) def test_skip_if_true():var worldassert var world# 不会被跳过的 pytest.mark.skipif(5%2 0, reason跳过用例的原因) def test_skip_if_false():var 2assert var 2pytest.mark.skip def test_skip():var HELLOassert var HELLO打印结果 test session starts collecting ... collected 3 itemstest_file.py::test_skip_if_true SKIPPED (跳过用例的原因) Skipped: 跳过用例的原因test_file.py::test_skip_if_false PASSED test_file.py::test_skip SKIPPED (unconditional skip) Skipped: unconditional skip 1 passed, 2 skipped in 0.03s pytest指定用例的执行顺序 需要安装插件 pip install pytest-ordering 通过如下装饰器来指定执行顺序order为整型值越小越先执行。 pytest.mark.run(ordern)n0的情况有装饰器的用例比没有顺序装饰器的用例先执行 n0的情况有装饰器的用例比没有顺序装饰器的用例后执行 例子 import pytestpytest.mark.run(order1) def test_1():var worldassert var worldpytest.mark.run(order0) def test_2():var 2assert var 2pytest.mark.run(order-1) def test_3():var HELLOassert var HELLOdef test_4():assert True执行结果 test session starts collecting ... collected 4 itemstest_file.py::test_2 PASSED test_file.py::test_1 PASSED test_file.py::test_4 PASSED test_file.py::test_3 PASSED 4 passed in 0.02s pytest用例执行重试 需要安装第三方插件 pip install pytest-rerunfailures 使用方式有两种 直接在命令行指定 reruns表示最大重试次数reruns-delay表示每次重试前的等待时间 pytest -s -q --reruns2 --reruns-delay5 {cases_path} --alluredir {report_path}使用pytest.mark.flaky装饰器,reruns表示最大重试次数reruns_delay表示每次重试前的等待时间如 pytest.mark.flaky(reruns3, reruns_delay2) 例 import pytestpytest.mark.run(order-1) def test_1():var worldassert var worldpytest.mark.flaky(reruns3, reruns_delay2) def test_4():assert False执行结果如下test_4执行了四次因为执行失败进行重试而执行的有三次。 test session starts collecting ... collected 2 itemstest_file.py::test_4 RERUN test_file.py::test_4 RERUN test_file.py::test_4 RERUN test_file.py::test_4 FAILED test_file.py:7 (test_4) pytest.mark.flaky(reruns3, reruns_delay2)def test_4():assert False E assert Falsetest_file.py:10: AssertionErrortest_file.py::test_1 PASSED 1 failed, 1 passed, 3 rerun in 6.15s 进程已结束退出代码为 1
http://www.w-s-a.com/news/771955/

相关文章:

  • 怎样用eclipse做网站可以做宣传图的网站
  • 哪里可以做游戏视频网站做网站平台应该注意哪些
  • 网站后期推广是谁来做网页制作步骤作答题
  • 全屋装修设计定制整装成都网站优化多少钱
  • html5购物网站模板一个网站两个数据库
  • 个人网站怎么做微信支付网站建设项目介绍
  • 建网站合同网站适配移动端和PC端
  • 网站建设培训机构哪里好html5开发wap网站
  • 免费自助建站源码学而思网校官网
  • 中国最大的网站制作公司青海省高等级公路建设管局网站
  • 建设网站对服务器有什么要求吗wordpress去除更新提示
  • 找个为公司做网站的手机端原神
  • 邯郸手机建站价格公众号开发者权限哪里添加
  • wordpress模板电子书下载站微信app官方免费下载
  • 从哪些方面进行网站建设如何做网站的实时画面
  • 设计网站公司收费西安小程序开发公司有哪些
  • 如何建网站赚取佣金哪个网站可以做免费宣传
  • 万网手机网站seo方法
  • 免费制作网站app百度首页纯净版
  • 支持api网站开发wordpress排版Markdown
  • 赤峰做网站的logo设计软件在线制作
  • iis网站批量导入苏州最新新闻事件今天
  • 甘肃省住房和城乡建设厅注册中心网站首页沈阳专业关键词推广
  • 网站怎么能在百度搜到网站开发费怎么做会计分录
  • 嘉定专业网站制作公司七星彩网站开发
  • 网站建设人员培训企业网站开发模型图
  • 自己开发一个网站应该怎么做国外设计网站 绿色的
  • 南昌外贸网站设计推广任务发布平台app
  • 建立网站成本书店网站建设可行性分析
  • 高端网站设计官网乌海学校网站建设