-3

I made a class in Python to perform some basic operations.

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

I don't understand why does the doctest failed for the add function.

Himanshu Mishra
  • 8,510
  • 12
  • 37
  • 74

1 Answers1

2

You need to add some spaces and a blank line into 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
Konstantin
  • 24,271
  • 5
  • 48
  • 65
  • @HimanshuMishra https://docs.python.org/2/library/doctest.html#how-are-docstring-examples-recognized doctest will look for a blank line or a line starting with `>>>` to determine when expected output ends – Konstantin Jul 12 '15 at 15:02