猿问

以漂亮的表格形式显示python单元测试结果

我正在编写一个Pythonic工具,该工具可验证某个系统的正确性。每个验证均以Python编写unittest,报告如下所示:


test_exclude_list_not_empty (__main__.TestRepoLists)

Assert the the exclude list is not empty ... ok

test_include_list_not_empty (__main__.TestRepoLists)

Assert the the include list is not empty ... ok

test_repo_list_not_empty (__main__.TestRepoLists)

Assert the the repo list is not empty ... ok

我认为,这种格式很难阅读,特别是对于非Python专家而言。是否有任何报告生成器可以生成表格形式的报告,例如:


+----------------------------------------------------------------+-----------+

| Test                                                           |  Status   |

+----------------------------------------------------------------+-----------+

| Assert the the exclude list is not empty                       |  OK       |

| Assert the the include list is not empty                       |  OK       |

| Assert the the repo list is not empty                          |  OK       |

| All the items in the include list should be in the repo list   |  OK       |

+----------------------------------------------------------------+-----------+

说明性该测试套件在远程终端上运行,因此我更喜欢命令行报告工具。


千巷猫影
浏览 284回答 4
4回答

青春有我

这并不完全是您要的内容,但是有几种方法可以在其中获得可读的测试输出:HTMLTestRunner以表格形式生成易于使用的HTML测试报告。这是一个示例报告。用于鼻子测试运行器的鼻子-html-输出插件unittest-xml-reporting-基于PyUnit的具有JUnit的测试运行程序,例如XML报告带有--with-xunit选项的鼻子将生成易于阅读和转换的junit xml样式报告另请参阅:如何在Python中产生html单元测试输出?HTML中的Python单元测试报告unittest彩色输出(对输出进行彩色也可以使结果可读)无论如何,如果您想在控制台中以表格形式查看测试结果,我认为一个好主意是基于HTMLTestRunner中的操作编写自己的鼻子插件或测试运行器。unittest.TestProgram希望能有所帮助。

慕村9548890

看看Twisted的Trial。默认情况下,它使用TreeReporter测试运行器,如下所示:它具有以下内容:这是一个命令行报告,只需运行:trial test_name.py彩色输出:红色表示失败,绿色表示成功该报告使用树状结构。它在测试所属的测试案例下显示测试,使您可以快速遍历结果以查找特定测试。(尽管它提供了更多的报告)。它还包括一个源自Python的测试库unittest.TestCase。您可以通过子类化使用此库 twisted.trial.unittest.TestCase。这提供了更多的断言方法。它包括为测试生成语句覆盖率的选项。
随时随地看视频慕课网APP

相关分类

Python
我要回答