Sphinx Doctest: test the code without comparing the output.
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sun Sep 22 08:12:51 EDT 2013
On Sat, 21 Sep 2013 21:15:48 -0700, Luca Cerone wrote:
> I am looking for a way to test the code while ignoring the output.
This makes no sense. If you ignore the output, the code could do ANYTHING
and the test would still pass. Raise an exception? Pass. SyntaxError?
Pass. Print "99 bottles of beer"? Pass.
I have sometimes written unit tests that just check whether a function
actually is callable:
ignore = function(a, b, c)
but I've come to the conclusion that is just a waste of time, since there
are dozens of other tests that will fail if function isn't callable. But
if you insist, you could always use that technique in your doctests:
>>> ignore = function(a, b, c)
If the function call raises, your doctest will fail, but if it returns
something, anything, it will pass.
--
Steven
More information about the Python-list
mailing list