首页 > 解决方案 > 为什么我的 pycharm 调试控制台输出未显示与 pytest 的正确差异

问题描述

我正在通过 Pycharm 在 Windows 上编写 python 3.7。我一直使用单独的终端窗口来运行我的测试,但我目前正在尝试原生 pycharm 测试运行器。我遇到了一个真正困扰我的问题。

如果我有这个测试:

def test__output_test():
    assert ['123\n', '456\n', '789\n'] == ['123\n', '455\n', '789\n']

当我通过命令行直接在 powershell 中运行它时python -m pytest -vv <path>,我得到了这个可爱的输出:

    def test__output_test():
>       assert ['123\n', '456\n', '789\n'] == ['123\n', '455\n', '789\n']
E       AssertionError: assert ['123\n', '456\n', '789\n'] == ['123\n', '455\n', '789\n']
E         At index 1 diff: '456\n' != '455\n'
E         Full diff:
E         - ['123\n', '455\n', '789\n']
E         ?              ^
E         + ['123\n', '456\n', '789\n']
E         ?              ^

但是当我通过 pycharm 的 pytest 测试运行器运行相同的测试时(-vv 在“附加参数”中设置),输出似乎截断了实际的差异显示:


def test__output_test():
>       assert ['123\n', '456\n', '789\n'] == ['123\n', '455\n', '789\n']
E       AssertionError: assert ['123\n', '456\n', '789\n'] == ['123\n', '455\n', '789\n']

..\tests\unit\test__output.py:4: AssertionError

似乎尝试在测试结果输出上方进行差异,但与我在 powershell 中得到的相比,这很糟糕:

FAILED                  [100%]
unit\test__output.py:2 (test__output_test)
['123
', '456
', '789
'] != ['123
', '455
', '789
']

<Click to see difference>

如果我单击“查看差异”链接弹出的差异查看器是“好的”,因为它会突出显示修改后的单词/符号,但它仍然会弄乱引用的换行符

我试图将我的 pycharm 终端设置为 powershell,但这并没有改变调试控制台的输出。我想知道是否需要设置一些额外的参数或设置来查看我的首选差异?

标签: pythonpowershelldebuggingpycharmpytest

解决方案


推荐阅读