doctests working both in Python 2.X and Python 3.X

Michele Simionato michele.simionato at gmail.com
Sun Apr 11 04:29:02 EDT 2010


I do not want to write two documentations for a module working both in
Python 2.X and Python 3.X.
To avoid that, I would need the ability to interpret doctests
according to the used Python version.

I mean something like that:

"""
Documentation of the module <mymodule>
-----------------------------------------------------------------

If you are using Python 2.X you can check that

  >>> <2.X code> # doctest: <some directive for 2.X>
  <2.X output>

whereas if you are using Python 2.X you can check that

  >>> <3.X code> # doctest: <some directive for 3.X>
  <3.X output>

Is something like that possible? If not, what are the options?
2to3 theoretically can converts the doctests, but in practice I have
seen that the doctests for my decorator module needs some manual
tweaking.



More information about the Python-list mailing list