Module doctest does not run

73 Views Asked by At

I am trying to use the doctest module to test code. I tried this example:

import doctest 

def areaTriangulo(base, altura):
    return 'El area del triangulo es: '+str((base*altura)/2)
    """
    funcion que nos devuelve el area de un triangulo
    >>> areaTriangulo(4,5)
    'El area del triangulo es: 20.0'
    """

doctest.testmod()

The test has a wrong answer on purpose, but the test tells me that there are no mistakes. Why?

1

There are 1 best solutions below

0
9769953 On BEST ANSWER

Make sure the docstring is at the top of the function definition; not at the bottom; otherwise Python won't recognise it as a docstring:

def areaTriangulo(base, altura):
    """
        
    funcion que nos devuelve el area de un triangulo
    
    >>> areaTriangulo(4,5)
    'El area del triangulo es: 20.0'
        
    """
    
    return 'El area del triangulo es: '+str((base*altura)/2)