在unittest中使用 logging 模块记录测试数据的方法
如下所示:
#-*-coding:utf-8-*-
importsys
importlogging
importunittest
importos
reload(sys)
sys.path.append(os.path.dirname(os.path.abspath(__file__))+r'\..')#返回脚本的路径
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s%(filename)s[line:%(lineno)d]%(levelname)s%(message)s',
datefmt='%a,%d%b%Y%H:%M:%S',
filename='log_test.log',
filemode='w')
logger=logging.getLogger()
classSomeTest(unittest.TestCase):
deftestSomething(self):
logger.debug("this=%r",'aaa')
logger.debug("that=%r",'bbb')
#etc.
self.assertEquals(3.14,3.14,'nonono')
if__name__=="__main__":
unittest.main()
生成的日志文件内容如下:
Wed,17May201715:04:53log_test.py[line:19]DEBUGthis='aaa' Wed,17May201715:04:53log_test.py[line:20]DEBUGthat='bbb'
PyDevunittesting:Howtocapturetextloggedtoalogging.Loggerin“CapturedOutput”
以上这篇在unittest中使用logging模块记录测试数据的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短