相关疑难解决方法(0)

在py.test测试中记录

我想在测试函数中放入一些日志语句来检查一些状态变量.

我有以下代码片段:

import pytest,os
import logging

logging.basicConfig(level=logging.DEBUG)
mylogger = logging.getLogger()

#############################################################################

def setup_module(module):
    ''' Setup for the entire module '''
    mylogger.info('Inside Setup')
    # Do the actual setup stuff here
    pass

def setup_function(func):
    ''' Setup for test functions '''
    if func == test_one:
        mylogger.info(' Hurray !!')

def test_one():
    ''' Test One '''
    mylogger.info('Inside Test 1')
    #assert 0 == 1
    pass

def test_two():
    ''' Test Two '''
    mylogger.info('Inside Test 2')
    pass

if __name__ == '__main__':
    mylogger.info(' About to start the tests ') …
Run Code Online (Sandbox Code Playgroud)

python logging pytest

66
推荐指数
5
解决办法
4万
查看次数

标签 统计

logging ×1

pytest ×1

python ×1