为什么doctest会失败?

时间:2015-07-12 14:52:29

标签: python class doctest

我在Python中创建了一个类来执行一些基本操作。

class perform(object):

    def add(self, first, second):
        """Adds two numbers
        >>>perform().add(1, 2)
        3
        Also adds string
        >>>perform().add('some', 'thing')
        'something'
        """
        return first+second

我不明白为什么doctest失败了add函数。

1 个答案:

答案 0 :(得分:2)

您需要在docstring

中添加一些空格和一个空行
class perform(object):
    def add(self, first, second):
        """Adds two numbers
        >>> perform().add(1, 2)
        3

        Also adds string
        >>> perform().add('some', 'thing')
        'something'
        """
        return first+second
相关问题