Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #54588
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-09-22 07:24 -0700 |
| References | (3 earlier) <523dbfd2$0$29988$c3e8da3$5496439d@news.astraweb.com> <0a3a0078-2d55-4cc8-bf8d-f7bede6af9f1@googlegroups.com> <523e5838$0$29988$c3e8da3$5496439d@news.astraweb.com> <48fb04f5-168e-4c91-83fe-f7a45efced25@googlegroups.com> <523edec3$0$29988$c3e8da3$5496439d@news.astraweb.com> |
| Message-ID | <d116e6db-5bd7-4d33-8097-8377dec5c171@googlegroups.com> (permalink) |
| Subject | Re: Sphinx Doctest: test the code without comparing the output. |
| From | Luca Cerone <luca.cerone@gmail.com> |
> 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...
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Sphinx Doctest: test the code without comparing the output. Luca Cerone <luca.cerone@gmail.com> - 2013-09-21 03:47 -0700
Re: Sphinx Doctest: test the code without comparing the output. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-21 12:27 +0000
Re: Sphinx Doctest: test the code without comparing the output. Luca Cerone <luca.cerone@gmail.com> - 2013-09-21 05:44 -0700
Re: Sphinx Doctest: test the code without comparing the output. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-21 15:48 +0000
Re: Sphinx Doctest: test the code without comparing the output. Luca Cerone <luca.cerone@gmail.com> - 2013-09-21 09:25 -0700
Re: Sphinx Doctest: test the code without comparing the output. Chris Angelico <rosuav@gmail.com> - 2013-09-22 11:33 +1000
Re: Sphinx Doctest: test the code without comparing the output. Luca Cerone <luca.cerone@gmail.com> - 2013-09-21 21:09 -0700
Re: Sphinx Doctest: test the code without comparing the output. Chris Angelico <rosuav@gmail.com> - 2013-09-22 14:25 +1000
Re: Sphinx Doctest: test the code without comparing the output. Ned Batchelder <ned@nedbatchelder.com> - 2013-09-22 09:39 -0400
Re: Sphinx Doctest: test the code without comparing the output. Luca Cerone <luca.cerone@gmail.com> - 2013-09-22 07:26 -0700
Re: Sphinx Doctest: test the code without comparing the output. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-23 00:36 +0000
Re: Sphinx Doctest: test the code without comparing the output. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-22 02:38 +0000
Re: Sphinx Doctest: test the code without comparing the output. Luca Cerone <luca.cerone@gmail.com> - 2013-09-21 21:15 -0700
Re: Sphinx Doctest: test the code without comparing the output. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-22 12:12 +0000
Re: Sphinx Doctest: test the code without comparing the output. Luca Cerone <luca.cerone@gmail.com> - 2013-09-22 07:24 -0700
Re: Sphinx Doctest: test the code without comparing the output. Neil Cerutti <neilc@norwich.edu> - 2013-09-23 13:42 +0000
Re: Sphinx Doctest: test the code without comparing the output. Luca Cerone <luca.cerone@gmail.com> - 2013-09-23 07:45 -0700
Re: Sphinx Doctest: test the code without comparing the output. Luca Cerone <luca.cerone@gmail.com> - 2013-09-23 07:51 -0700
Re: Sphinx Doctest: test the code without comparing the output. Skip Montanaro <skip@pobox.com> - 2013-09-23 10:14 -0500
Re: Sphinx Doctest: test the code without comparing the output. Neil Cerutti <neilc@norwich.edu> - 2013-09-23 16:44 +0000
Re: Sphinx Doctest: test the code without comparing the output. Neil Cerutti <neilc@norwich.edu> - 2013-09-23 16:53 +0000
Re: Sphinx Doctest: test the code without comparing the output. Luca Cerone <luca.cerone@gmail.com> - 2013-09-23 11:54 -0700
csiph-web