'Doctest doesen't give output

My problem is that whenever I use doctest I receive no errors, no exceptions and no output at all. I checked if my file has ".py" extension, I tried running it through command line (in case VSC might have been the cause of this), I also reinstalled python interpreter (so currently it is 3.10.4). I tried using various example code like for example the one at the beginning of doctest official documentation and other example code pieces from various websites and I always receive no output at all.

I checked if I would receive output if I call and print the call of a function that I was about to test and then I receive output of the function I was testing but no doctest output. So even when I use a simple piece of code like this:

import doctest
def add(x, y):
   """
   >>> add(2, 2)
   4
   >>> add(1, 1)
   2
   """

   return x + y
doctest.testmod()

It produces no output at all.



Solution 1:[1]

According to the documentation, there will be no output unless the example fails.

If you would like to see doctests detailed report anyway, you should run the script with -v parameter, or change the doctest.testmod() to doctest.testmod(verbose=True), both will work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 daniel