在unittest中使用 logging 模块记录测试数据的方法,unittestlogging
在unittest中使用 logging 模块记录测试数据的方法,unittestlogging
如下所示:
# -*- 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+request+unittest实现接口测试框架集成实例,pythonu
- python中logging包的使用总结,pythonlogging
- 详解Python自建logging模块,python自建logging
- 详解Python之unittest单元测试代码,pythonunittest
- python中 logging的使用详解,pythonlogging
- python+requests+unittest API接口测试实例(详解),requestsunit
- Django日志模块logging的配置详解,djangologging
- 利用Python中unittest实现简单的单元测试实例详解,pyth
- python logging 日志轮转文件不删除问题的解决方法,
- Python中内置的日志模块logging用法详解,pythonlogging
评论关闭