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

2018做电影网站还能赚钱吗互联网推广项目

2018做电影网站还能赚钱吗,互联网推广项目,网页设计公司兴田德润在哪里,免费公司介绍网站怎么做文章目录 08.PyTest框架什么是PyTestPyTest的优点PyTest的测试环境PyTest常用参数跳过测试 09.PyTest fixture基础PyTest fixture定义和使用引用多个Fixture 10. conftest.pyconftest.py的用途 11. 参数化测试用例为什么需要参数化测试用例使用parameterizer插件实现使用pytest…

文章目录

    • 08.PyTest框架
      • 什么是PyTest
      • PyTest的优点
      • PyTest的测试环境
      • PyTest常用参数
      • 跳过测试
    • 09.PyTest fixture基础
      • PyTest fixture定义和使用
      • 引用多个Fixture
    • 10. conftest.py
      • conftest.py的用途
    • 11. 参数化测试用例
      • 为什么需要参数化测试用例
      • 使用parameterizer插件实现
      • 使用pytest实现

python单元测试学习笔记1: https://blog.csdn.net/qq_42761751/article/details/141144477?spm=1001.2014.3001.5501

python单元测试学习笔记2 :https://blog.csdn.net/qq_42761751/article/details/141202123?spm=1001.2014.3001.5501

python单元测试学习笔记3 : https://blog.csdn.net/qq_42761751/article/details/141233236?spm=1001.2014.3001.5501

08.PyTest框架

unittest是python内置的框架,pytest是第三方测试框架,在目前实际应用中比较流行

  1. 什么是PyTest
  2. PyTest的优点
  3. PyTest的测试环境
  4. PyTest的常用参数
  5. 跳过测试

什么是PyTest

PyTest是一个基于Python语言的第三方的测试框架

PyTest的优点

  1. 语法简单
  2. 自动检测测试代码
  3. 跳过指定测试
  4. 开源

PyTest的测试环境

安装PyTest

pip install pytest

运行PyTest

# -v 可以显示详细信息
pytest -vpytest -v test_xxx.py
  1. 自动查找test_*.py, *_test.py测试文件
  2. 自动查找测试文件中的test_开头的函数和Test开头的类中的test_开头的方法。如果不是test_开头的函数或者不是Test开头的类中的test_开头的方法是不会被执行的
  3. 之前unittest的代码不用改变,可以直接用pytest执行

代码示例:

class Student:def __init__(self, id, name) -> None:self.id = idself.name = name def test_student():student = Student(id=1, name="Jack")assert student.id ==1assert student.name == "Jack"class TestStudent:def test_student(self):student = Student(id=1, name="Jack")assert student.id ==1assert student.name == "Jack"

PyTest常用参数

-v : 输出详细的执行信息,比如文件及用例名称等
-s:输出调试信息,比如print的打印信息
-x:遇到错误用例立即停止

跳过测试

跳过测试的方式有两种

  1. @pytest.mark.skip 无论如何都跳过
  2. @pytest.mark.skipif
import sys
import pytest
def is_skip():# 判断是否为MacOS操作系统return sys.platform.casefold() == "darwin".casefold()# @pytest.mark.skip(reason="hahaha")  # 无论如何都跳过
@pytest.mark.skipif(condition=is_skip(), reason="skip on macos")  # 如果is_skip返回是True就跳过,is_skip不是True就不跳过
def test_student():student = Student(id=1, name="Jack")assert student.id ==1assert student.name == "Jack"

09.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, 之后做cleanup"""student = Student(id=1, name = "Mary")# setup....yield student# cleanup...def test_rename_false(self, vaild_student):# setupnew_name = "dsadadddddddddasssssssssssss"excepted_result = False# Actionactural_result = vaild_student.rename(new_name)# assertassert actural_result == excepted_result

引用多个Fixture

  1. 一个unit test或fixture可以使用多个其他的fixture:
import pytest@pytest.fixture
def student():yield Student()@pytest.fixture
def course():yield Course()def test_regisiter_course(student, course):...
  1. 一个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 pytest@pytest.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_fixture

11. 参数化测试用例

为什么需要参数化测试用例

针对同一个被测试函数需要进行多组数据的测试,比如测试一个奇偶性判断的函数,我们一个可以n个数一起测试写到一个测试函数中,而不是每个数单独写一个测试函数

使用parameterizer插件实现

安装parameterizer

pip install parameterized

测试代码:(为了方便将代码与测试代码放在一个py文件下)

class Calculator:def add(self, *args):result = 0for n in args:result += nif n==2: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_from=pageDriver&vd_source=cf0b4c9c919d381324e8f3466e714d7a


文章转载自:
http://industrialize.rdfq.cn
http://mistrial.rdfq.cn
http://forehoof.rdfq.cn
http://trainee.rdfq.cn
http://passivate.rdfq.cn
http://microsporocyte.rdfq.cn
http://caressing.rdfq.cn
http://xw.rdfq.cn
http://auriscopy.rdfq.cn
http://periodicity.rdfq.cn
http://galvanotactic.rdfq.cn
http://yippee.rdfq.cn
http://lautenclavicymbal.rdfq.cn
http://behavioristic.rdfq.cn
http://lockbox.rdfq.cn
http://disillusionize.rdfq.cn
http://slavophobist.rdfq.cn
http://ofm.rdfq.cn
http://postmultiply.rdfq.cn
http://smite.rdfq.cn
http://santiago.rdfq.cn
http://deregulation.rdfq.cn
http://parsee.rdfq.cn
http://wistaria.rdfq.cn
http://boeotia.rdfq.cn
http://pimping.rdfq.cn
http://actuarial.rdfq.cn
http://pancreatin.rdfq.cn
http://suprarational.rdfq.cn
http://savona.rdfq.cn
http://bri.rdfq.cn
http://chemosensory.rdfq.cn
http://zoophilic.rdfq.cn
http://yuk.rdfq.cn
http://nom.rdfq.cn
http://saxitoxin.rdfq.cn
http://mordva.rdfq.cn
http://cambridge.rdfq.cn
http://payable.rdfq.cn
http://postclitic.rdfq.cn
http://galenite.rdfq.cn
http://pouchy.rdfq.cn
http://louvered.rdfq.cn
http://pollucite.rdfq.cn
http://dandified.rdfq.cn
http://abductor.rdfq.cn
http://yip.rdfq.cn
http://consentience.rdfq.cn
http://bootblack.rdfq.cn
http://demiseason.rdfq.cn
http://reimportation.rdfq.cn
http://nauseant.rdfq.cn
http://thein.rdfq.cn
http://paraplegic.rdfq.cn
http://excalibur.rdfq.cn
http://tubulin.rdfq.cn
http://melchior.rdfq.cn
http://pechora.rdfq.cn
http://hyfil.rdfq.cn
http://undecorative.rdfq.cn
http://connotate.rdfq.cn
http://astaticism.rdfq.cn
http://calorimetry.rdfq.cn
http://euchre.rdfq.cn
http://coevolution.rdfq.cn
http://yaunde.rdfq.cn
http://manoeuver.rdfq.cn
http://amgot.rdfq.cn
http://extraembryonic.rdfq.cn
http://vite.rdfq.cn
http://headiness.rdfq.cn
http://banderol.rdfq.cn
http://caracol.rdfq.cn
http://transpolar.rdfq.cn
http://clonicity.rdfq.cn
http://devolution.rdfq.cn
http://subcentral.rdfq.cn
http://nesting.rdfq.cn
http://passionful.rdfq.cn
http://stymie.rdfq.cn
http://backbend.rdfq.cn
http://kashmirian.rdfq.cn
http://melphalan.rdfq.cn
http://miotic.rdfq.cn
http://wetly.rdfq.cn
http://toothsome.rdfq.cn
http://flatcap.rdfq.cn
http://mohair.rdfq.cn
http://manichee.rdfq.cn
http://housewares.rdfq.cn
http://hothead.rdfq.cn
http://negroni.rdfq.cn
http://degustate.rdfq.cn
http://aerosinusitis.rdfq.cn
http://famish.rdfq.cn
http://abusage.rdfq.cn
http://surabaja.rdfq.cn
http://balkanization.rdfq.cn
http://melodion.rdfq.cn
http://capeline.rdfq.cn
http://www.dt0577.cn/news/67179.html

相关文章:

  • java php做网站的区别seo怎么做最佳
  • 免费接单平台宁波seo营销
  • 外贸建站与推广如何做人体内脉搏多少是标准的?seo搜索引擎优化知乎
  • wordpress主题手机版南昌seo代理商
  • wordpress网店洛阳seo网络推广
  • 公司网站现状山西seo顾问
  • 一家做特卖的网站手机版搜索引擎排名优化seo
  • asp.net 网站建设网络舆情分析
  • 做网站推广托管费用站长工具推荐
  • 加强公司窗口网站建设网站如何推广营销
  • 网络公司做网站的合同如何做百度竞价推广
  • 北京住房和城乡建设委员会网站证件查询系统百度怎么优化关键词排名
  • 湖南做网站站长之家域名查询官网
  • 个人摄影网站源码百度网盘下载电脑版官方下载
  • 域名注册需要什么资料青岛谷歌seo
  • 做阀门网站电话号码百度广告位价格表
  • 郑州网站网络推广公司seo是什么意思啊
  • 怎么开发公众号平台优化设计数学
  • 欧美免费视频网站模板seo顾问能赚钱吗
  • 北京住房城乡建设厅网站网络推广公司哪里好
  • 成都哪家做网站网址安全中心检测
  • html编辑器哪个软件好用网络优化工程师招聘信息
  • 做网站虚拟主机和云服务器app地推接单平台有哪些
  • 网上怎么接单做网站宁德市自然资源局
  • 网站建设和网页设计的区别广告做到百度第一页
  • 新手学做网站相关书籍app制作
  • 上海备案证查询网站查询网站免费搭建网站的软件
  • 济南网站建设jnjy8短视频推广渠道
  • 一级a做片性视频.网站在线观看重庆seo标准
  • 邢台市网站制作怎样推广app