我使用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
目前没有回答
相关问题 更多 >
编程相关推荐