欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

在unittest中使用 logging 模塊記錄測(cè)試數(shù)據(jù)的方法

 更新時(shí)間:2018年11月30日 15:05:17   作者:HeatDeath  
今天小編就為大家分享一篇在unittest中使用 logging 模塊記錄測(cè)試數(shù)據(jù)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

如下所示:

# -*- coding:utf-8 -*-
import sys
import logging
import unittest
import os

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()


class SomeTest(unittest.TestCase):
 def testSomething(self):
  logger.debug("this= %r", 'aaa')
  logger.debug("that= %r", 'bbb')
  # etc.
  self.assertEquals(3.14, 3.14, 'nonono')

if __name__ == "__main__":
 unittest.main()

生成的日志文件內(nèi)容如下:

Wed, 17 May 2017 15:04:53 log_test.py[line:19] DEBUG this= 'aaa'
Wed, 17 May 2017 15:04:53 log_test.py[line:20] DEBUG that= 'bbb'

PyDev unittesting: How to capture text logged to a logging.Logger in “Captured Output”

以上這篇在unittest中使用 logging 模塊記錄測(cè)試數(shù)據(jù)的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論