log.p文件
from loguru import logger
import time
import os
# 解析配置文件中所写的路径
PATH = lambda a: os.path.abspath(os.path.join(os.path.dirname(__file__), a))
now = time.strftime(‘%Y-%m-%d %H:%M:%S‘)
# 从配置文件获取日志路径
# log_path = PATH(get_Path_elements(‘Log_path‘)[‘path‘])
log_path = PATH(‘../Logs/‘) # 暂时写死,就存这个位置下
# 判断日志文件夹是否存在
if not os.path.exists(log_path):
# 递归创建
os.makedirs(log_path)
def log():
logger.add(sink=os.path.join(log_path, now + ".log"), # 日志记录的位置
level="DEBUG", # 日志记录的等级
retention=‘7 days‘, # 日志记录
enqueue=False, # 日志 异步记录
backtrace=False, # 完全的记录描述
diagnose=False)
return logger
test_demo.py文件
import pytest
from log import log
log = log()
@pytest.mark.parametrize(‘user‘, [‘shichao‘, ‘xiaoming‘])
def test_demo_1(user):
log.info(user)
assert 1 == 1
log.info("-----" + user)
# pytest.main(["test_demo_1"])
记:pytest在pycharm中会运行多次,命令行运行正常的问题
原文:https://www.cnblogs.com/shanshan-test/p/15098559.html