[Python-Dev] doctest and inspect.getmodule

Tim Peters tim.peters at gmail.com
Sat Sep 11 19:46:20 CEST 2004


[Johannes Gijsbers]
> I just checked in a change to inspect.getmodule (without running the tests
> beforehand, not a smart move) which broke a whole bunc of tests for doctest.
> The tests mostly seem to fail because doctest can find modules for objects it
> previously couldn't.

All failures were like that.  test_doctest.py contains lots of
"recursive" uses of doctest, where test_doctest.py functions contain
docstrings that themselves contain both definitions of functions with
their own docstrings, and calls to doctest functions.  Before your
change, functions defined inside docstrings and dynamically compiled
by doctest.py were a mystery to inspect.getmodule(), but after your
change getmodule() figured it knew which module they came from.  This
had no effect on doctest doctests that showed succeeding doctest
examples, but for doctest doctests showing failing doctest examples,
the failure-output "and which doctest failed?" meta line changed, from
stuff like:

    Line 3, in f

to stuff like:

    File "C:\Code\python\lib\test\test_doctest.py", line 4, in f

Couldn't be more obvious <wink>.

> I think the change is basically correct,

Me too.

> but I'm not sure how to fix doctest.

That's OK, I already did.  doctest didn't need any changes, but the
expected output in test_doctest.py had to be fiddled.

...
> Oh, I promise I'll run the tests before checking in next time.

Everyone is entitled to one screwup per century.  This was yours <wink>.


More information about the Python-Dev mailing list