PyTest 上每个测试显示的百分比是什么意思?

What's the meaning of the percentages displayed for each test on PyTest?

我刚开始使用 Pytest 进行测试,我 运行 遇到了一个小但烦人的挂断。

在命令行测试会话结果中,我看到我的测试通过了,但对于某些测试,显示的百分比不是 100%。

通过一些积极的日志记录,我能够确认我的测试按预期通过。

我的问题是:为收集的测试显示的百分比是什么意思?

示例:

platform win32 -- Python 3.7.0a4, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
rootdir: C:\api-check, inifile:
collected 5 items

test_Me.py ...                                                           [ 60%]
test_env.py ..                                                           [100%]

========================== 5 passed in 6.04 seconds ===========================

这是一个临时的进度条。

它显​​示到目前为止完成的 "percentage of work" -- 最有可能的是,完成的测试总数除以 运行 的测试总数(它在开始时预先计算)。

如果您的测试 运行 时间更长,您可能会看到行中的数字在 运行 遍历特定文件时发生变化。

自 3.3 (2017) 版以来,它是 Pytest 中包含的功能之一。

正如我的战友@ivan_pozdeev所说,这是一个进度指标indeed

这是一个示例,您收集了 4 个测试:

$ pytest test.py -v
================================ test session starts =============================
platform linux -- Python 3.6.7, pytest-4.4.0, py-1.8.0, pluggy-0.9.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/ivanleoncz/git/pysd
collected 4 items                                                                           
test.py::test_active_services PASSED                                        [ 25%]
test.py::test_enabled_services PASSED                                       [ 50%]
test.py::test_is_enabled PASSED                                             [ 75%]
test.py::test_is_active PASSED                                              [100%]

============================== 4 passed in 0.55 seconds ==========================
  • 100% 的测试/收集的测试数量 == 25% 的进度,从一个测试到另一个