在鼻子测试中打印不同的详细描述以及测试名称python [英] Print a different long description in nose tests along with test name python

查看:83
本文介绍了在鼻子测试中打印不同的详细描述以及测试名称python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用命令:

nosetests test.py

运行此命令时,仅打印描述的第一行. 我想要整个描述以及测试名称.我该怎么办?

When this is run only the first line of the description gets printed. I want the whole description along with the test name. How do i do that?

test.py文件

import unittests

class TestClass(unittest.TestCase):

    def test_1(self):
       """this is a long description //
              continues on second line which does not get printed """
       some code;
       self.assertTrue(True)

    def test_2(self):
       """this is another or different long description //
              continues on second line which does not get printed """
       some code;
       self.assertTrue(True)


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

推荐答案

Unittest是

Unittest is documented as only showing the first line of the test method's docstring. But you could override the default implementation of shortDescription method to customise that behaviour:

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)

演示:

$ nosetests -v example.py 
this is a long description //
              continues on second line ... ok
this is another or different long description //
              continues on second line which also gets printed :) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.000s

OK

有人写了一个鼻子插件来解决这个确切的烦恼,也许您会对使用它感兴趣.在这里是: https://bitbucket.org/natw/nose-description-fixer -plugin/

Someone wrote a nose plugin to fix this exact annoyance, maybe you'd be interested to use that. Here it is: https://bitbucket.org/natw/nose-description-fixer-plugin/

这篇关于在鼻子测试中打印不同的详细描述以及测试名称python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆