Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用pytest记录毫秒数 目标_Python_Logging_Pytest - Fatal编程技术网

Python 使用pytest记录毫秒数 目标

Python 使用pytest记录毫秒数 目标,python,logging,pytest,Python,Logging,Pytest,在pytest的日志输出上显示毫秒 我试过的东西 pytest文档假装使用兼容的字符串进行日志记录,因此我不能像datetime.strftime pytest.ini [pytest] log_cli = True log_cli_format = %(asctime)s %(levelname)s %(message)s log_cli_level = DEBUG #log_cli_date_format = %H:%M:%S:%f [pytest] log_cli = True log_

pytest
的日志输出上显示毫秒

我试过的东西 pytest文档假装使用兼容的字符串进行日志记录,因此我不能像
datetime.strftime

pytest.ini

[pytest]
log_cli = True
log_cli_format = %(asctime)s %(levelname)s %(message)s
log_cli_level = DEBUG
#log_cli_date_format = %H:%M:%S:%f
[pytest]
log_cli = True
log_cli_format = %(asctime)s.%(msecs)03d %(levelname)s %(message)s
log_cli_level = DEBUG
test\u this.py

导入日志
def test_me():
logging.info('something')
我不明白的是
pytest

设置用于格式化实时日志消息的兼容字符串

但是,默认情况下,日志
%(asctime)s
以毫秒为单位

创建日志记录时的人类可读时间。默认情况下,格式为“2003-07-08 16:49:45896”(逗号后的数字是时间的毫秒部分)

问题:
是否有任何简单的解决方案来显示毫秒?默认情况下日志记录包的工作方式?它一定是黑的吗?

即使pytest覆盖了日志记录的默认日期格式,来自的额外的
%(msecs)d
似乎正好解决了此类问题

pytest.ini

[pytest]
log_cli = True
log_cli_format = %(asctime)s %(levelname)s %(message)s
log_cli_level = DEBUG
#log_cli_date_format = %H:%M:%S:%f
[pytest]
log_cli = True
log_cli_format = %(asctime)s.%(msecs)03d %(levelname)s %(message)s
log_cli_level = DEBUG
输出

$ python3 -m pytest
==== test session starts ====
[...]

test_this.py::test_me
----- live log call -----
19:56:57.249 INFO something
PASSED                                                                                                                          [100%]

=== 1 passed in 0.01s ===
谢谢不过,我会使用
%(毫秒)03d
。这样,5毫秒而不是249毫秒将被打印为
19:56:57.005
,而不是
19:56:57.5