Module doctest does not run

Question:

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?

Asked By: Antonio delasheras

||

Answers:

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)
Answered By: 9769953
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.