在unittest中使用 logging 模塊記錄測試數(shù)據(jù)的方法
如下所示:
# -*- 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 模塊記錄測試數(shù)據(jù)的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
python中ThreadPoolExecutor線程池和ProcessPoolExecutor進程池
這篇文章主要介紹了python中ThreadPoolExecutor線程池和ProcessPoolExecutor進程池,文章圍繞主題相關(guān)資料展開詳細的內(nèi)容介紹,具有一定的參考價值,感興趣的小伙伴可以參考一下2022-06-06
python中torch.load中的map_location參數(shù)使用
在PyTorch中,torch.load()函數(shù)是用于加載保存模型或張量數(shù)據(jù)的重要工具,map_location參數(shù)為我們提供了極大的靈活性,具有一定的參考價值,感興趣的可以了解一下2024-03-03
Django代碼性能優(yōu)化與Pycharm Profile使用詳解
本文通過一個簡單的實例一步一步引導(dǎo)讀者對其進行全方位的性能優(yōu)化,這篇文章主要給大家介紹了關(guān)于Django代碼性能優(yōu)化與Pycharm Profile使用的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下2018-08-08
利用Python批量循環(huán)讀取Excel的技巧分享
這篇文章主要為大家詳細介紹了何用Python批量循環(huán)讀取Excel,文中的示例代碼講解詳細,對我們的學(xué)習(xí)或工作有一定的幫助,感興趣的可以了解一下2023-07-07
python urllib和urllib3知識點總結(jié)
在本篇內(nèi)容里小編給大家分享了一篇關(guān)于python urllib和urllib3知識點總結(jié)內(nèi)容,對此有興趣的朋友們可以學(xué)習(xí)參考下。2021-02-02

