[b0043] python 归纳 (二八)_python测试使用快速上手
参考
Python必会的单元测试框架 —— unittest
# -*- coding: utf-8 -*-
"""
测试代码组织,整理( 非可执行) """ import unittest
from test_mathfunc import TestMathFunc
from HTMLTestRunner import HTMLTestRunner ### 1 def add(a, b):
return a+b def minus(a, b):
return a-b def multi(a, b):
return a*b def divide(a, b):
return a/b ### 2
class TestMathFunc(unittest.TestCase):
"""Test mathfuc.py""" ## 1 @classmethod
def setUpClass(cls):
print "This setUpClass() method only called once." @classmethod
def tearDownClass(cls):
print "This tearDownClass() method only called once too." ## 2
def setUp(self):
print "do something before test.Prepare environment." def tearDown(self):
print "do something after test.Clean up." ## 3
def test_add(self):
"""Test method add(a, b)"""
print "add"
self.assertEqual(3, add(1, 2))
self.assertNotEqual(3, add(2, 2)) def test_minus(self):
"""Test method minus(a, b)"""
print "minus"
self.assertEqual(1, minus(3, 2)) def test_multi(self):
"""Test method multi(a, b)"""
print "multi"
self.assertEqual(6, multi(2, 3)) @unittest.skip("I don't want to run this case.")
def test_divide(self):
"""Test method divide(a, b)"""
print "divide"
self.assertEqual(2, divide(6, 3))
self.assertEqual(2.5, divide(5, 2)) if __name__ == '__main__':
suite = unittest.TestSuite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestMathFunc))
# suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestMathFunc2))
# suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestMathFunc3)) # tests = [TestMathFunc("test_add"), TestMathFunc("test_minus"), TestMathFunc("test_divide")]
# suite.addTests(tests) with open('HTMLReport.html', 'w') as f:
# runner = unittest.TextTestRunner(stream=f, verbosity=2)
runner = HTMLTestRunner(stream=f,
title='MathFunc Test Report',
description='generated by HTMLTestRunner.',
verbosity=2
)
runner.run(suite)
[b0043] python 归纳 (二八)_python测试使用快速上手的更多相关文章
- 【Python五篇慢慢弹】快速上手学python
快速上手学python 作者:白宁超 2016年10月4日19:59:39 摘要:python语言俨然不算新技术,七八年前甚至更早已有很多人研习,只是没有现在流行罢了.之所以当下如此盛行,我想肯定是多 ...
- [b0015] python 归纳 (一)_python组织方式
结论: xxx.yyyy yyyy 可以是 类.类对象.函数.变量 xxx 可以是 包.模块.类 代码: ref1.py # -*- coding: utf-8 -*- import os class ...
- 入门python:《Python编程快速上手让繁琐工作自动化》中英文PDF+代码
入门推荐学习<python编程快速上手>前6章是python的基础知识,通俗易懂地讲解基础,初学者容易犯错的地方,都会指出来.从第三章开始,每章都有一个实践项目,用来巩固前面所学的知识. ...
- 《Python操作SQLite3数据库》快速上手教程
为什么使用SQLite数据库? 对于非常简单的应用而言,使用文件作为持久化存储通常就足够了,但是大多数复杂的数据驱动的应用需要全功能的关系型数据库.SQLite的目标则是介于两者之间的中小系统.它有以 ...
- 使用python+pychram进行API测试(接口测试)初级STEP 1
花了一天时间安装了解了下最基本的python+pychram进行API测试,下面这个可以指导自己以后入门:基本的开发级别还需要学习 1.python下载地址:https://www.python.or ...
- 为 Python Server Pages 和 Oracle 构建快速 Web 开发环境。
为 Python Server Pages 和 Oracle 构建快速 Web 开发环境. - 在水一方 - 博客频道 - CSDN.NET 为 Python Server Pages 和 Oracl ...
- 从0开始的Python学习001快速上手手册
假设大家已经安装好python的环境了. Windows检查是否可以运行python脚本 Ctrl+R 输入 cmd 在命令行中输入python 如果出现下面结果,我们就可以开始python的学习了. ...
- python多线程在渗透测试中的应用
难易程度:★★★ 阅读点:python;web安全; 文章作者:xiaoye 文章来源:i春秋 关键字:网络渗透技术 前言 python是门简单易学的语言,强大的第三方库让我们在编程中事半功倍,今天, ...
- Python编程快速上手-让繁琐工作自动化-第二章习题及其答案
Python编程快速上手-让繁琐工作自动化-第二章习题及其答案 1.布尔数据类型的两个值是什么?如何拼写? 答:True和False,使用大写的T和大写的F,其他字母是小写. 2.3个布尔操作符是什么 ...
随机推荐
- Visual Studio 2019使用码云设置过滤忽略的文件或文件夹(ignore file)
Visual Studio 2019使用码云的时候,会遇到 “Git failed with a fatal error.error: open(".vs/{{项目名称}}/Server/s ...
- Shell(五):函数
linux shell 可以用户定义函数,然后在shell脚本中可以随便调用. shell中函数的定义格式: [ function ] funname [()] { action; [return i ...
- IT兄弟连 HTML5教程 DIV+CSS的兼容性问题
使用DIV+CSS布局网页其实是很容易的事情,但各种浏览器之间的不兼容性问题,加大了页面布局的难度,给程序员带来很多不便,于是需要花费更多的时间在调试各种浏览器的兼容性上.因为部分CSS属性在不同的浏 ...
- Splash 学习笔记
一.介绍 Splash 跟之前我们介绍的 Selenium ( 参考 Selenium 与自动化测试 -- <Selenium 2 自动化测试实战>读书笔记) 很类似,都可以理解成一个浏览 ...
- MongoDB(二):在Windows环境安装MongoDB
1. 在Windows环境安装 1.1 MongoDB下载 要在Windows上安装MongoDB,首先打开MongoDB官网:https://www.mongodb.com/download-cen ...
- GPS定位的偏移校正(WGS84与火星坐标互转)
地图坐标系目前包括: 地球坐标 (WGS84) WGS84:World Geodetic System 1984,是为GPS全球定位系统使用而建立的坐标系统. 国际标准,从 GPS 设备中取出的数据的 ...
- 如何实现用户的历史记录功能(最多n条)
使用容量为n的队列存储历史记录 使用标准库collections中的deque,它是一个双端循环队列 from collections import deque q = deque([], 5) #参 ...
- 团队项目之Alpha阶段项目复审
组的名字和链接 优点 缺点,bug报告 最终名次 六姑娘 https://www.cnblogs.com/liujiamei/p/11992659.html 团队的小程序功能齐全,这说明团队在需求分析 ...
- [Go] 轻量服务器框架基础TCP服务模块
框架要先把整体的结构定义好,一般都是在$GOPATH目录的src下建立自己的目录 zinterface是一些接口的定义 znet就是接口的具体实现 IServer.go package zinterf ...
- Unity3D 使用Socket处理数据并将数据 在UGUI、NGUI上显示出来
Unity3d 不支持C#的线程直接调用Unity3D 主线程才能实现的功能.例如:给UGUI text 赋值.改变Color值等.怎样解决这个问题呢?使用一个Loom脚本. 按照惯例贴上代码. 首先 ...