py.test
的 --verbose
选项需要显示断言失败的完整差异,但这也会在执行期间显示每个测试的全名(很吵)。
我希望在断言失败时显示完整的差异,但我只希望在测试运行时显示单个 .
。有办法做到这一点吗?
最佳答案
不幸的是,似乎没有配置或命令行标志,因为它是硬编码的 deep inside pytest : 当你定义 --verbose
时,你会得到整个包。但是,我设法想出了这个 hackish hack。将以下函数放入您的 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
这本质上是一个猴子补丁,依赖于 pytest 内部结构,不能保证与 future 的版本兼容并且丑陋如罪。您还可以根据命令行参数的一些其他自定义配置使此补丁有条件。
关于python - 如何在没有详细测试进度的情况下显示详细的 py.test 差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30938780/