使用日志记录时的Pytest错误

时间:2018-12-03 10:04:02

标签: python logging pytest

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

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

它会导致错误:

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

它在记录消息“它在这里崩溃”之后执行此操作,这是代码。

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之后不进行日志记录或仅禁用日志记录就可以正常运行,并且拆卸正常完成。

1 个答案:

答案 0 :(得分:1)

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

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

为使您更加聪明,请在问题解决之前向master的pytest进行验证,我会在发现时间后将测试添加到测试人员中

谢谢:+1: