Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在nose测试中打印不同的长描述以及测试名称python_Python_Nose_Python Unittest - Fatal编程技术网

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

在nose测试中打印不同的长描述以及测试名称python,python,nose,python-unittest,Python,Nose,Python Unittest,我正在使用命令: nosetests test.py 运行此操作时,仅打印描述的第一行。 我想要完整的描述和测试名称。我该怎么做 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

我正在使用命令:

nosetests test.py
运行此操作时,仅打印描述的第一行。 我想要完整的描述和测试名称。我该怎么做

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是测试方法的docstring的一部分。但是您可以覆盖
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)
演示:


有人写了一个鼻子插件来解决这个问题,也许你会有兴趣使用它。这是:

我想我以前在某处见过黑客攻击,但无论如何+1。
$ 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