1 year ago

#340924

test-img

Elise

doctest not returning a result

I have looked at this question, and have seen this tutorial, but still haven't been able to figure out what is going wrong.

I have the following code, just to try out doctest:

import doctest

def fizz_buzz(numbers):
    """ 
    >>> numbers = [45, 22, 15, 39, 10]
    >>> fizz_buzz(numbers)
    >>> numbers
    ['fizzbuzz', 22, 'fizzbuzz', 'fiszssz', 'buzz']
    """ 

    for i in range(len(numbers)):
        num = numbers[i]
        if num % 3 == 0 and num % 5 == 0:
            numbers[i] = 'fizzbuzz'
        elif num % 3 == 0:
            numbers[i] = 'fizz'
        elif num % 5 == 0:
            numbers[i] = 'buzz'

But when I run python doctest.py -v or python3 -m doctest doctest.py the code runs with no output, even though there should be an error message due to fiszssz in the testing.

I thought the issue might be that the file was called doctest.py, but even after renaming it to othertest.py it still produces no output.

What am I missing?

python

testing

doctest

0 Answers

Your Answer

Accepted video resources