gpt4 book ai didi

python - 使用日志记录时拆解中的 Pytest 错误

转载 作者:行者123 更新时间:2023-11-28 18:05:37 24 4
gpt4 key购买 nike

当我运行我的测试时,如果我在它屈服后使用 ctrl-c(键盘中断)取消它,它应该在 yield 语句之后继续运行代码。但是,如果我在启用日志记录的情况下运行它:

pytest test_logging_error.py --log-cli-level info

它会导致错误:

AttributeError: 'NoneType' object has no attribute 'resume_capturing'

它在记录“It crashes here”消息后执行此操作,这是代码。

from time import sleep
import pytest
import logging


@pytest.fixture(scope="module")
def connection():
numbers = []
for i in range(10):
numbers.append(i)
yield numbers
logging.info("It crashes here")
for i in range(10):
print("foo")


def test_error(connection):
logging.info("Running a test")
sleep(10000)

如果我在 yield 之后不记录日志或只是禁用日志记录运行它,它运行正常并且拆卸正确完成。

最佳答案

这是一个实际的 pytest 错误,我相信 https://github.com/pytest-dev/pytest/pull/4487修复它(它刚刚被合并到 master 中)

但感谢 https://github.com/pytest-dev/pytest/issues/4500 中的错误报告我们现在有一个针对该问题的最小复制器,可以将其添加为回归测试

如果问题得到解决,请通过 master 的 pytest 进行更清晰的确认,我会在有时间时将测试添加到测试套件中

谢谢:+1:

关于python - 使用日志记录时拆解中的 Pytest 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53591387/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com