在nose测试中打印不同的长描述以及测试名称python

2024-04-25 04:49:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用命令:

nosetests test.py

运行此命令时,只打印第一行描述。 我要完整的描述和测试名称。我该怎么做?在

在测试.py文件

^{pr2}$

Tags: 文件pytest命令名称nosetestspr2
1条回答
网友
1楼 · 发布于 2024-04-25 04:49:57

Unittest是测试方法docstring的documented as only showing the first line。但是您可以重写shortDescription方法的默认实现来定制该行为:

import unittest

class TestClass(unittest.TestCase):

    def shortDescription(self):
        return self._testMethodDoc

    def test_1(self):
       """this is a long description //
              continues on second line """
       self.assertTrue(True)

    def test_2(self):
       """this is another or different long description //
              continues on second line which also gets printed :) """
       self.assertTrue(True)

if __name__ == '__main__':
    unittest.main(verbosity=2)

演示:

^{pr2}$

有人写了一个鼻子插件来解决这个问题,也许你会有兴趣使用它。在这里:https://bitbucket.org/natw/nose-description-fixer-plugin/

相关问题 更多 >