python自动化测试之从命令行运行测试用例with verbosity

yipeiwu_com6年前Python基础

本文实例讲述了python自动化测试之从命令行运行测试用例with verbosity,分享给大家供大家参考。具体如下:

实例文件recipe3.py如下:

class RomanNumeralConverter(object): 
  def __init__(self, roman_numeral): 
    self.roman_numeral = roman_numeral 
    self.digit_map = {"M":1000, "D":500, "C":100, "L":50, "X":10,  
             "V":5, "I":1} 
  def convert_to_decimal(self): 
    val = 0 
    for char in self.roman_numeral: 
      val += self.digit_map[char] 
    return val 
 
   
import unittest 
class RomanNumeralConverterTest(unittest.TestCase): 
     
  def test_parsing_millenia(self): 
    value = RomanNumeralConverter("M") 
    self.assertEquals(1000, value.convert_to_decimal()) 
     
  def test_parsing_century(self): 
    '''THIS is a error test case''' 
    value = RomanNumeralConverter("C") 
    self.assertEquals(10, value.convert_to_decimal()) 
     
     
     
if __name__ == "__main__": 
  suite = unittest.TestLoader().loadTestsFromTestCase(RomanNumeralConverterTest) 
  unittest.TextTestRunner(verbosity=2).run(suite)

运行结果如下图所示:

这就是测试用例失败的样子。

希望本文所述对大家的Python程序设计有所帮助

相关文章

TensorFlow dataset.shuffle、batch、repeat的使用详解

直接看代码例子,有详细注释!! import tensorflow as tf import numpy as np d = np.arange(0,60).reshape([6...

Python实现程序的单一实例用法分析

本文实例讲述了Python实现程序的单一实例用法。分享给大家供大家参考。具体如下: 这里先使用win32ui.FindWindow查找窗口名字,如果不存在则会抛出一个异常 impor...

python简单实现旋转图片的方法

本文实例讲述了python简单实现旋转图片的方法。分享给大家供大家参考。具体实现方法如下: # rotate an image counter-clockwise using the...

Python中的字符串查找操作方法总结

基本的字符串位置查找方法 Python 查找字符串使用 变量.find("要查找的内容"[,开始位置,结束位置]),开始位置和结束位置,表示要查找的范围,为空则表示查找所有。查找到后会返...

python实现简单日期工具类

本文实例为大家分享了python实现简单日期工具类的具体代码,供大家参考,具体内容如下 import datetime import time DATETIME_FORMAT =...