python - 如何在没有详细测试进度的情况下显示详细的 py.test 差异?

标签 python pytest

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/

相关文章:

python - 如何测试自定义handler500?

python - Pytest 从父目录运行?

Pythoncursor.execute() 与 MySQL UPDATE 导致语法错误

python - 匹配列中的值并返回 pandas | 中的另一列Python

django - 如何在 pytest-django 中模拟 django 设置属性

python - pytest 是否应该从虚拟环境中的依赖模块收集测试?

python - 为什么 `py.test --last-failed` 会跳过许多测试,尽管之前没有测试失败?

python - Raspberry Pi 上的 py.test 和 pytest : Differences ?

python - 如何在 heroku 上托管 cython web 应用程序?

python - 创建一个包含 2 个变量的列表