生成报告时,如何在显示详细信息链接的捕获日志中摆脱看起来是 ASCII 的内容?从命令行运行时似乎出现了 ASCII,但不使用 PyCharm(addopts = --html=./logs/report.html --self-contained-html)。图片: 显示 ASCII 的报告
另外,您如何摆脱testscript
名称和行号?这在命令行以及 PyCharm 中运行时会出现。图片:
显示testscript
名称和行号的报告
测试用例文件:
import os
import sys
import pytest
import logging
LOGGER = logging.getLogger(__name__)
def test_one():
print('')
print("(test_one) TEST1")
LOGGER.info("(test_two) INFO1:")
LOGGER.warning("(test_two) WARNING1:")
LOGGER.error("(test_two) ERROR1:")
LOGGER.critical("(test_two) CRITICAL1:")
apple = 'red'
assert apple == 'red'
def test_two():
print('')
print("(test_two) TEST2")
LOGGER.info("(test_two) INFO2:")
LOGGER.warning("(test_two) WARNING2:")
LOGGER.error("(test_two) ERROR2:")
LOGGER.critical("(test_two) CRITICAL2:")
pear = 'green'
assert pear == 'green'
日志文件:
[pytest]
log_cli = 1
log_cli_level = DEBUG
log_cli_format = %(message)s
log_file = logs/pytest.log
log_file_level = DEBUG
log_file_format = %(asctime)s %(levelname)8s: %(message)s
log_file_date_format=%Y%m%d%H%M%S
日志文件输出:
20200611090159 INFO: (test_two) INFO1:
20200611090159 WARNING: (test_two) WARNING1:
20200611090159 ERROR: (test_two) ERROR1:
20200611090159 CRITICAL: (test_two) CRITICAL1:
20200611090159 INFO: (test_two) INFO2:
20200611090159 WARNING: (test_two) WARNING2:
20200611090159 ERROR: (test_two) ERROR2:
20200611090159 CRITICAL: (test_two) CRITICAL2: