在unittest中使用 logging 模块记录测试数据的方法
更新时间:2018年11月30日 15:05:17 作者:HeatDeath
今天小编就为大家分享一篇在unittest中使用 logging 模块记录测试数据的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
如下所示:
# -*- 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()
生成的日志文件内容如下:
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 模块记录测试数据的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
python中ThreadPoolExecutor线程池和ProcessPoolExecutor进程池
这篇文章主要介绍了python中ThreadPoolExecutor线程池和ProcessPoolExecutor进程池,文章围绕主题相关资料展开详细的内容介绍,具有一定的参考价值,感兴趣的小伙伴可以参考一下2022-06-06
python中torch.load中的map_location参数使用
在PyTorch中,torch.load()函数是用于加载保存模型或张量数据的重要工具,map_location参数为我们提供了极大的灵活性,具有一定的参考价值,感兴趣的可以了解一下2024-03-03
Django代码性能优化与Pycharm Profile使用详解
本文通过一个简单的实例一步一步引导读者对其进行全方位的性能优化,这篇文章主要给大家介绍了关于Django代码性能优化与Pycharm Profile使用的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考下2018-08-08


最新评论