时间:2021-05-22
如下所示:
# -*- coding:utf-8 -*-import sysimport loggingimport unittestimport osreload(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 模块记录测试数据的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
logging日志模块:是用来记录日志的模块,一般记录用户在软件中的操作 使用方法:模板直接拿来用,手动修改#logging的配置信息(模板)import
代码使用方法见注释#-*-coding:UTF-8-*-fromlxmlimportetreesource=u'''测试数据1测试数据2测试数据3图片'''#从
详解使用python的logging模块在stdout输出前言: 使用python的logging模块时,除了想将日志记录在文件中外,还希望在前台执行pyth
测试步骤1.导入unittest模块importunittest2.编写测试的类继承unittest.TestCaseclassTester(unittest.
使用logging模块,记录日志信息安装模块pip3installlogging脚本示例vimflask_api_logging.py#!/usr/bin/en