极简 Pytest 输出?

now*_*wox 4 python pytest

当我运行时pytest,我得到一个非常详细的输出,带有丑陋的分隔符===============================================================================================================================

例如:

======================================================================================================= test session starts =======================================================================================================
platform linux -- Python 3.6.8, pytest-5.0.1, py-1.8.0, pluggy-0.12.0
rootdir: /home/ycr/info1-labo-04
collected 1 item                                                                                                                                                                                                                  

test_armstrong.py .                                                                                                                                                                                                         [100%]

==================================================================================================== 1 passed in 0.03 seconds =====================================================================================================
Run Code Online (Sandbox Code Playgroud)

是否有可能获得更紧凑的输出,例如:

...
----------------------------------------------------------------------
Ran 3 tests in 5.63s

OK
Run Code Online (Sandbox Code Playgroud)

mne*_*rov 8

你可以尝试这个 pytest 命令

pytest -q --show-capture=no --disable-warnings --tb=no tests.py
Run Code Online (Sandbox Code Playgroud)

它应该向您显示最少的信息

-q-> 安静输出

--show-capture=no-> 控制如何在失败的测试中显示捕获的 stdout/stderr/log。

--disable-warnings-> 如果有任何警告不要显示

--tb=no-> 如果有任何回溯,请不要显示它们


如果您使用 pytest 版本 < 6.0,则可以选择--no-print-logs.

  • `--no-print-logs` 命令行选项[在版本 5.4 中已弃用,并在 6.0 中删除](https://docs.pytest.org/en/7.1.x/deprecations.html?highlight=print%20logs #无打印日志命令行选项)。 (2认同)