Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.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 带有xdist的Pytest未打印所有测试的日志_Python_Pytest_Pytest Xdist - Fatal编程技术网

Python 带有xdist的Pytest未打印所有测试的日志

Python 带有xdist的Pytest未打印所有测试的日志,python,pytest,pytest-xdist,Python,Pytest,Pytest Xdist,我使用pytest编写了一个端口扫描程序测试。它接收一个包含ip地址列表的json文件,然后使用parametrize对每个ip地址运行测试。使用Pythonlogging模块创建带有自定义日志消息的日志文件。通过使用pytest xdist进行并行执行,我还可以显著减少运行时 问题在于,当使用pytest xdist运行测试时,只有一个测试记录到日志文件中,而CLI输出与预期完全一致。例如,如果测试针对4个不同的ip地址运行4次,则只有其中一个运行的结果记录到日志文件中。确实被记录的测试似乎是

我使用pytest编写了一个端口扫描程序测试。它接收一个包含ip地址列表的json文件,然后使用
parametrize
对每个ip地址运行测试。使用Python
logging
模块创建带有自定义日志消息的日志文件。通过使用
pytest xdist
进行并行执行,我还可以显著减少运行时

问题在于,当使用
pytest xdist
运行测试时,只有一个测试记录到日志文件中,而CLI输出与预期完全一致。例如,如果测试针对4个不同的ip地址运行4次,则只有其中一个运行的结果记录到日志文件中。确实被记录的测试似乎是随机的,并且在运行之间会发生变化。在并行执行测试时,登录到外部文件的正确方法是什么

# Contents of pytest.ini
[pytest]
log_cli = 1
log_cli_level = CRITICAL
log_cli_format = %(message)s

log_file = port_scanner.log
log_file_level = DEBUG
log_file_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)
log_file_date_format=%Y-%m-%d %H:%M:%S