网站建设的开题报告,qq电脑版官方入口,做外贸都做哪些网站好免费下载,siren wordpress发现用print在console里面打不出来#xff0c;所以查了一下关于pytest的log配置#xff0c;记录 首先需要在根目录新建 pytest.ini
如果你只需要使用print打印日志的话#xff0c;就只需要这样写
[pytest]
addopts -s
#addopts 是一个配置项#xff0c;用于指定传递给 p… 发现用print在console里面打不出来所以查了一下关于pytest的log配置记录 首先需要在根目录新建 pytest.ini
如果你只需要使用print打印日志的话就只需要这样写
[pytest]
addopts -s
#addopts 是一个配置项用于指定传递给 pytest 的额外命令行选项。
#-s 是 pytest 的一个命令行选项表示禁用输出捕获允许测试中的 print 语句将输出直接打印到控制台。
#因此这个配置告诉 pytest 在运行时使用 -s 选项使得测试中的输出能够直接显示在终端上而不是被 #pytest 捕获并隐藏。这在调试和查看详细信息时很有用。
就可以在pytest中在console中看到print打印的东西呢。
但是如果需要log配置的话。
[pytest]
log_cli true
log_cli_level INFO
log_cli_format %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)
log_cli_date_format %Y-%m-%d %H:%M:%S 然后在test中这样就可以使用了 import pytest
import loggingloglogging.getLogger(__name__)pytest.fixture
def xxxx():...yield xxxxdef test_xxx(xxxx):log.error(Log Something)...
如果要和flask的log全局配置结合使用请参考我的另一篇blogFlask 3.x log全域配置(包含pytest)-CSDN博客