在unittest中使用 logging 模块记录测试数据的方法
2018-12-03 09:26
1296 查看
如下所示:
# -*- 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 模块记录测试数据的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- 在unittest中使用 logging 模块记录测试数据的方法
- 在 unittest 中使用 logging 模块记录测试数据
- 《Python Web开发测试驱动方法》第2章“unittest模块扩展功能测试”
- Python中的测试模块unittest和doctest的使用教程
- 使用unittest里面的discover()方法组织测试用例
- 使用PYTHON的UNITTEST做测试
- Django 中使用 logging 模块记录系统日志
- 使用vs2010的Coded UI Test实现数据驱动的用户自动登录测试
- python中使用sys模板和logging模块获取行号和函数名的方法
- 使用Google Unit Test 测试你的C++代码
- VS2012 Unit Test(Void, Action, Func) —— 对无返回值、使用Action或Func作为参数、多重载的方法进行单元测试
- python标准日志模块logging的使用方法
- [Python]logging模块使用basicConfig后记录日志重复问题
- python中使用sys模板和logging模块获取行号和函数名的方法
- python标准日志模块logging的使用方法
- log4j和commons.logging日志记录的使用方法
- android中测试方法的使用Test
- 使用vs2010的Coded UI Test实现数据驱动的用户自动登录测试
- 记录一下PHP数组数据分页的方法 array_slice() 函数的使用
- 使用JDBC插入多数据测试的3种实现方法