pytest pytest.ini 配置日志输出至文件

pytest pytest.ini 配置日志输出至文件_第1张图片

 创建pytest.ini 文件 

[pytest]
log_file =pytest_log.txt
log_file_level = INFO
log_file_date_format = %Y-%m-%d %H:%M:%S
log_file_format = %(asctime)s | %(filename)s | %(funcName)s | line:%(lineno)d | %(levelname)s | %(message)s
import pytest
import logging

def test_01():
    logging.info('这是测试用例01的info...')
    logging.warning('这是测试用例01的warning...')
    logging.error('这是测试用例01的error...')
    assert 1 == 1

if __name__ == '__main__':
    pytest.main(['-v','test_case.py'])

 

 pytest pytest.ini 配置日志输出至文件_第2张图片

 pytest pytest.ini 配置日志输出至文件_第3张图片

你可能感兴趣的:(#,pytest测试框架,pytest)