Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.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
Python unittest,如何在报告中显示TestCase方法的docstring?_Python_Python Unittest - Fatal编程技术网

Python unittest,如何在报告中显示TestCase方法的docstring?

Python unittest,如何在报告中显示TestCase方法的docstring?,python,python-unittest,Python,Python Unittest,题目是自我解释的。 有没有办法 class Foo(TestCase): def test_bar(self): """ a docstring """ 要使UnitTest报告显示整个文档字符串 我已经读到docstring的第一行会打印成这样 """ a docstring """ 不换行工作 我读过这个问题: 但是,它是关于删除docstring的,我不知道如何覆盖shortDescription来显示完整的docstring。我没有尝试过这个 它说,在对

题目是自我解释的。 有没有办法

class Foo(TestCase):
  def test_bar(self):
    """
    a docstring
    """
要使UnitTest报告显示整个文档字符串

我已经读到docstring的第一行会打印成这样

""" a docstring """
不换行工作

我读过这个问题:

但是,它是关于删除docstring的,我不知道如何覆盖shortDescription来显示完整的docstring。

我没有尝试过这个

它说,在对

负责的方法是TestCase.shortDescription,您可以 在测试用例中重写

详情如下:

doc = self._testMethodDoc 
return doc and doc.split("\n")[0].strip() or None
因此,您可以将第二行修改为

return doc
屈服

class MyTests(unittest.TestCase):
    #  ....
    def shortDescription(self):
        doc = self._testMethodDoc 
        return doc
如果您反对使用未记录的self.\u testMethodDoc,则它是testMethod.\uuuu doc\uuuuuuuuu的直接副本,该副本是在TestCase中创建的。\uuuuu init\uuuuuuuuu通过

测试用例的变量很少。它们被重命名的可能性很小,但您也可以从源代码处询问作者:

 47  __author__ = "Steve Purcell" 
 48  __email__ = "stephen_purcell at yahoo dot com" 
我没有试过这个

它说,在对

负责的方法是TestCase.shortDescription,您可以 在测试用例中重写

详情如下:

doc = self._testMethodDoc 
return doc and doc.split("\n")[0].strip() or None
因此,您可以将第二行修改为

return doc
屈服

class MyTests(unittest.TestCase):
    #  ....
    def shortDescription(self):
        doc = self._testMethodDoc 
        return doc
如果您反对使用未记录的self.\u testMethodDoc,则它是testMethod.\uuuu doc\uuuuuuuuu的直接副本,该副本是在TestCase中创建的。\uuuuu init\uuuuuuuuu通过

测试用例的变量很少。它们被重命名的可能性很小,但您也可以从源代码处询问作者:

 47  __author__ = "Steve Purcell" 
 48  __email__ = "stephen_purcell at yahoo dot com" 

不要在测试方法中使用docstring,使用自解释方法名称我确实使用自解释方法名称,但我无法详细描述函数在函数名称中的行为。由于我的单元测试正在增长,我不想在测试文件中阅读此描述。。。因此,如果我能让它显示在报告中,至少在测试失败的情况下,那将是非常棒的。解决方案在这个答案中是正确的,返回self.\u testMethodDoc。因为这个属性没有文档记录并且有下划线,使用它安全耐用吗?我确信它不会被重命名/删除,也不会在测试方法中使用docstring,使用自解释方法名称我确实使用自解释方法名称,但我无法详细描述函数在函数名称中的行为。由于我的单元测试正在增长,我不想在测试文件中阅读此描述。。。因此,如果我能让它显示在报告中,至少在测试失败的情况下,那将是非常棒的。解决方案在这个答案中是正确的,返回self.\u testMethodDoc。因为这个属性没有文档记录并且有下划线,使用它安全耐用吗?我确信它不会很快被重命名/删除