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

培训网站平台如何推广如何安装wordpress

培训网站平台如何推广,如何安装wordpress,企业营销型网站案例,云阳网站建设文章目录 08.PyTest框架什么是PyTestPyTest的优点PyTest的测试环境PyTest常用参数跳过测试 09.PyTest fixture基础PyTest fixture定义和使用引用多个Fixture 10. conftest.pyconftest.py的用途 11. 参数化测试用例为什么需要参数化测试用例使用parameterizer插件实现使用pytest… 文章目录 08.PyTest框架什么是PyTestPyTest的优点PyTest的测试环境PyTest常用参数跳过测试 09.PyTest fixture基础PyTest fixture定义和使用引用多个Fixture 10. conftest.pyconftest.py的用途 11. 参数化测试用例为什么需要参数化测试用例使用parameterizer插件实现使用pytest实现 python单元测试学习笔记1 https://blog.csdn.net/qq_42761751/article/details/141144477?spm1001.2014.3001.5501 python单元测试学习笔记2 https://blog.csdn.net/qq_42761751/article/details/141202123?spm1001.2014.3001.5501 python单元测试学习笔记3 https://blog.csdn.net/qq_42761751/article/details/141233236?spm1001.2014.3001.5501 08.PyTest框架 unittest是python内置的框架pytest是第三方测试框架在目前实际应用中比较流行 什么是PyTestPyTest的优点PyTest的测试环境PyTest的常用参数跳过测试 什么是PyTest PyTest是一个基于Python语言的第三方的测试框架 PyTest的优点 语法简单自动检测测试代码跳过指定测试开源 PyTest的测试环境 安装PyTest pip install pytest运行PyTest # -v 可以显示详细信息 pytest -vpytest -v test_xxx.py自动查找test_*.py, *_test.py测试文件自动查找测试文件中的test_开头的函数和Test开头的类中的test_开头的方法。如果不是test_开头的函数或者不是Test开头的类中的test_开头的方法是不会被执行的之前unittest的代码不用改变可以直接用pytest执行 代码示例 class Student:def __init__(self, id, name) - None:self.id idself.name name def test_student():student Student(id1, nameJack)assert student.id 1assert student.name Jackclass TestStudent:def test_student(self):student Student(id1, nameJack)assert student.id 1assert student.name JackPyTest常用参数 -v : 输出详细的执行信息比如文件及用例名称等 -s输出调试信息比如print的打印信息 -x遇到错误用例立即停止 跳过测试 跳过测试的方式有两种 pytest.mark.skip 无论如何都跳过pytest.mark.skipif import sys import pytest def is_skip():# 判断是否为MacOS操作系统return sys.platform.casefold() darwin.casefold()# pytest.mark.skip(reasonhahaha) # 无论如何都跳过 pytest.mark.skipif(conditionis_skip(), reasonskip on macos) # 如果is_skip返回是True就跳过is_skip不是True就不跳过 def test_student():student Student(id1, nameJack)assert student.id 1assert student.name Jack09.PyTest fixture基础 PyTest fixture定义和使用 使用pytest.fixture定义 定义一个student.py class Student:def __init__(self, id, name) - None:self.id idself.name namedef rename(self, new_name: str) -bool:if 3 len(new_name) 10:self.name new_namereturn Truereturn False def vaild_student(self) -bool:if self.name:return 3 len(self.name) 10测试代码 import pytest from student import Studentclass TestStudent:pytest.fixturedef vaild_student(self):使用yield很方便在测试用力之前做setup, 之后做cleanupstudent Student(id1, name Mary)# setup....yield student# cleanup...def test_rename_false(self, vaild_student):# setupnew_name dsadadddddddddasssssssssssssexcepted_result False# Actionactural_result vaild_student.rename(new_name)# assertassert actural_result excepted_result引用多个Fixture 一个unit test或fixture可以使用多个其他的fixture import pytestpytest.fixture def student():yield Student()pytest.fixture def course():yield Course()def test_regisiter_course(student, course):...一个fixture可以被一个test引用多次 pytest.fixture def student():return Student()pytest.fixture def course():return Course()pytest.fixture def course_student(course, student):course.add_student(student)return coursedef test_regisiter_course(course_student, course):...10. conftest.py conftest.py的用途 使得fixture可以被多个文件中的测试用例复用 在项目目录下直接新建conftest.py import pytestpytest.ficture def male_student_fixture():student Student(id 1, name Jack) 在测试代码中可直接使用,pytest会自动找到这个文件 def test_vaild_gender_true(self, male_student_fixture):expected_result Trueactural_result male_student_fixture.vaild_gender()assert actual_result expected_result方式2在conftest.py中引入fixture建议使用这种方式 # conftest.py import pytest from student_fixture import male_student_fixture11. 参数化测试用例 为什么需要参数化测试用例 针对同一个被测试函数需要进行多组数据的测试比如测试一个奇偶性判断的函数我们一个可以n个数一起测试写到一个测试函数中而不是每个数单独写一个测试函数 使用parameterizer插件实现 安装parameterizer pip install parameterized测试代码为了方便将代码与测试代码放在一个py文件下 class Calculator:def add(self, *args):result 0for n in args:result nif n2:result 5return resultdef is_odd(self, num:int)-bool:return num%2 !0import unittest import parameterized class TestCalculator(unittest.TestCase):parameterized.expend([[1,True], [2, False]])def test_is_odd(self,num, excepted_out):# SetUpcal Calculator()# Actionactural_result cal.is_odd(num)# assertassert actural_result excepted_out使用pytest实现 import pytest pytest.mark.parametrize(num, excepted_result, [(1, True), (2,False)]) def test_is_odd(num, excepted_result):# setupcal Calculator()# Actionresult cal.is_odd(num)# assertassert result excepted_result本文参考https://www.bilibili.com/video/BV1z64y177VF/?spm_id_frompageDrivervd_sourcecf0b4c9c919d381324e8f3466e714d7a
http://www.dnsts.com.cn/news/107596.html

相关文章:

  • 宁德北京网站建设小说主题 wordpress
  • 网站如何做站内站wordpress如何通过后台增加主菜单
  • 多语言网站天津网站设计开发
  • 哪些网站可以做爬虫实验网站网站建设网站
  • 企业网站管理中心北京朝阳区网站建设
  • 恩施seo整站优化哪家好wordpress 本地 搭建
  • 手机网站建设渠道成都建设网站报价
  • 自己做网站需要花钱吗大网站的建设重点
  • 自己怎么做鲜花网站文章标题-栏目名称-网站名 dede
  • 医药网站开发佛山网站建设骏域
  • 微信表情包制作网站如何利用云服务器进行网站建设
  • 做装修广告网站好酷炫网站
  • php做网站怎么样苏州工业园区gdp
  • 汽车行业市场分析那个网站做的好一个服务器可以备案几个网站吗
  • 内网建站软件网站栏目名称
  • 企业网站教程 优帮云unas做网站服务器
  • 物流网站和数据库建设四川住房和城乡建设厅网站不能打开
  • 内蒙网站建设wordpress安装插件慢
  • 做网站页面遇到的问题了解深圳网站页面设计
  • 北京微信网站建设报价单seo搜索优化工具
  • 东莞凤岗企业网站建设推广杭州 电商设计网站建设
  • 深圳提供网站建设服务平台常州网站运营公司
  • 关于旅游网站建设的方案10个零网站建设
  • 网站内部资源推广百度推广关键词质量度
  • 网站建设吉金手指专业13seo超级外链发布
  • 制作网站的商家vps云主机可以做网站
  • 2014最新网站模板-网页模板免费下载-风格吧网站开发语言用什么好
  • 广东营销型网站建设网页qq登录保护开启不了
  • 泗阳网站建设网站开发经济可行性分析怎么写
  • 网站创建流程包括哪些步骤电子商务网站多少钱