سؤال

class Test:
    def __init__(self):
        pass

    '''
    This function parses a name according to following rules - 

    >>> Test().name('Kshitiz Sharma')
    Sharma, Kshitiz

    '''
    def name(self, name):
        name = name.split()
        return name[1] + ", " + name[0]

if __name__ == "__main__":
    import doctest
    doctest.testmod()

The output is -

4 items had no tests:
    __main__
    __main__.Test
    __main__.Test.__init__
    __main__.Test.name
0 tests in 4 items.
0 passed and 0 failed.
Test passed.

Where is my test?

هل كانت مفيدة؟

المحلول

Put the docstring inside the method.

def name(self, name):
    '''
    This function parses a name according to following rules - 

    >>> name('Kshitiz Sharma')
    <BLANKLINE>

    '''
    pass

Also to run the test on a method correctly you'll need to actually instantiate the class to have access to the method during the test itself:

    >>> t = Test(); t.name('Kshitiz Sharma')
    <BLANKLINE>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top