Python 如果没有详细的测试进度,如何显示详细的py.test差异?
Python 如果没有详细的测试进度,如何显示详细的py.test差异?,python,pytest,Python,Pytest,py.test的--verbose选项是显示断言失败时的完整差异所必需的,但这也会显示执行期间每个测试的全名(这是有噪声的) 我希望在断言失败时显示完整的差异,但我只希望在测试运行时显示单个。有办法做到这一点吗?不幸的是,似乎没有配置或命令行标志,因为这是硬编码的:当您定义--verbose时,您就得到了整个包。然而,我已经设法想出了这个黑客。将以下函数放入conftest.py: def pytest_configure(config): terminal = config.plugi
py.test
的--verbose
选项是显示断言失败时的完整差异所必需的,但这也会显示执行期间每个测试的全名(这是有噪声的)
我希望在断言失败时显示完整的差异,但我只希望在测试运行时显示单个
。有办法做到这一点吗?不幸的是,似乎没有配置或命令行标志,因为这是硬编码的:当您定义--verbose
时,您就得到了整个包。然而,我已经设法想出了这个黑客。将以下函数放入conftest.py
:
def pytest_configure(config):
terminal = config.pluginmanager.getplugin('terminal')
BaseReporter = terminal.TerminalReporter
class QuietReporter(BaseReporter):
def __init__(self, *args, **kwargs):
BaseReporter.__init__(self, *args, **kwargs)
self.verbosity = 0
self.showlongtestinfo = self.showfspath = False
terminal.TerminalReporter = QuietReporter
这本质上是一个monkey补丁,依赖于pytest内部,不能保证与未来版本兼容,就像sin一样丑陋。您还可以根据命令行参数的其他自定义配置将此修补程序设置为有条件的。基于@bereal的答案
(这很好,但应该跟进一些pytest更改)
这很有效。你应该考虑创建一个<代码> Py.Test<(代码)>插件,它添加了一个命令行选项来修补这个行为!我将考虑为内部终端插件做一个拉请求,谢谢。
def pytest_configure(config):
terminal = config.pluginmanager.getplugin('terminal')
class QuietReporter(terminal.TerminalReporter):
@property
def verbosity(self):
return 0
@property
def showlongtestinfo(self):
return False
@property
def showfspath(self):
return False
terminal.TerminalReporter = QuietReporter