doctest in Pythonwin
Terry Reedy
tjreedy at udel.edu
Sat Aug 10 14:58:28 EDT 2002
<posted and mailed>
"Tim Peters" <tim.one at comcast.net> wrote in message
news:mailman.1028945596.24353.python-list at python.org...
> [Terry Reedy]
<'complaing' about...>
> > >>> *** Tester.merge: 'doctesttest' in both testers; summing
outcomes.
> I'm betting you ran a doctest more than once in your PythonWin
session,
Of course. Once the call is there, its there (unless #ed out, which
maybe it mostly should be until the file is finished).
>and that you didn't get this message the very first time you ran a
doctest.
I started over today and you are correct: it only appears on
subsequent runs. Upon adding 'verbose=1', I also discovered that the
message is a symptom of a much deeper problem: doctest *does not
reread* the revised doc strings. So yesterday, when I first ran with
no tests, there never were any. Today it ran all 7, but continued to
run the same 7 even after I changed doc strings to and and subtract
examples.
> As explained in doctest's large docstrings <wink>, advanced uses of
doctest
> rely on that doctest maintains state across invocations, in order to
merge
> results from multiple runs. If you run a test with a given name
more than
> once, the grand-summary accumulator inside doctest spits out that
message to
> let you know you're (at best) double-counting. It would often be
better if
> IDEs spawned a new process when running files (there are many ways
you can
> get tripped up in IDLE, and I expect PythonWin too, by that
sys.modules
> persists across script runs).
>
> In this particular case, you can worm around it by doing
>
> import doctest
> doctest.master = None
>
> before each doctest run (that destroys doctest's accumulator -- but
doctest
> will create it again, so you have to keep doing this).
The added line nulling doctest.master cures the symptom but not the
disease: the merge message no longer appears but doc strings are
*still* not reread. Reloading the doctest module does not work, but
reloading the module being tested does! So here is my doctest.__doc__
patch: At the end of the section beginning
---
NORMAL USAGE
In normal use, end each module M with:
def _test():
import doctest, M # replace M with your module's name
return doctest.testmod(M) # ditto
---
add
---
If you are using doctest for files edited in an IDE (such as idle,
Pythonwin) and you run a file with doctest enabled more than once in
an editing sesssion, _test may need two more lines to reset:
def _test():
import doctest, M # replace M with your module's
name
doctest.master = None
reload(M) # ditto
return doctest.testmod(M) # ditto
----
Terry J. Reedy
More information about the Python-list
mailing list