> 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. >
if you try the commands, you can see that the tests fail.. for example .. doctest:: >>> raise Exception("test") will fail with this message: File "utils.rst", line 5, in default Failed example: raise Exception("test") Exception raised: Traceback (most recent call last): File "/usr/lib/python2.7/doctest.py", line 1289, in __run compileflags, 1) in test.globs File "<doctest default[0]>", line 1, in <module> raise Exception("test") Exception: test So to me this seems OK.. "Print" will fail as well... > > > 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. > > I understand your point, but now I am not writing unit tests to check the correctness of the code. I am only writing a tutorial and assuming that the code is correct. What I have to be sure is that the code in the tutorial can be executed correctly, and some commands print verbose output which can change. It is not enough to write >>> ignore = function(a,b,c) won't work because the function still prints messages on screen and this causes the failure of the test... -- https://mail.python.org/mailman/listinfo/python-list