首页 > 解决方案 > 在 pytest-ing 时禁用每个测试“点”

问题描述

我有大约 10^5 个测试的参数化测试套件。因此,我正在调试引发的错误,即使用-x标志。像这样:

pytest tests.py -x

这里的问题是这个命令使终端与.每个测试相对应。这是不希望的(因为我没有任何 xfaild 或其他东西 - 仅通过与否;并且由于测试的数量):

............................................................................................................................................................................................................ [  5%]
............................................................................................................................................................................................................ [ 11%]
............................................................................................................................................................................................................ [ 17%]

如何禁用这个“点”并只留下进度条?也许一些插件?试过了-q,但点还在打印。

标签: pythonterminalpytest

解决方案


你可以pytest_report_teststatus()在你的conftest.py. 它返回一个元组结果类别、短字母和详细词。

def pytest_report_teststatus(report, config):
    if report.passed and report.when == "call":
        return report.outcome, "", report.outcome.upper()

每次测试都会调用钩子 3 次,report.when设置为"setup","call""teardown""call"如果测试在阶段中通过,上面的回调将 shortletter 设置为空字符串。


推荐阅读