[TIP] Building a unittest.TestCase from a doctest

Laura Creighton lac at openend.se
Thu Dec 20 02:13:45 PST 2007

Warning: I haven't read this list for over a week, and missed the 
first part of this thread.  So I may be proposing a solution that
doesn't fix the problem that you are actually trying to solve ...


If you download the py.test lib you will find a nice program I
wrote to automatically convert unittests to the py.tests

Since nose uses the same format for writing tests, you ought to
be able to run the results of this with nose as easily as with
py.test.  (But, again warning, I haven't tried this).   Then you
are only stuck integrating nose with doctest, which presumably you
already know how to do.

Laura Creighton

In a message of Tue, 18 Dec 2007 10:48:31 PST, Titus Brown writes:
>-> >In my situation, I would like to load doctests from
>-> >/over/there/module.py into a file 'test.py' that is loaded with other
>-> >unittest.TestCases, and have the doctest run together with the other
>-> >test cases.
>-> A module may contain multiple tests.  I don't understand why you would
>-> want a single test case?  This would be like taking any test suite and
>-> saying you want to treat it as a single test case. I must be  
>-> misunderstanding you.
>Hi, Jim,
>no, you understand me right.
>My real goal is to get the tests to *run* under the aegis of a different
>module; I'm not really all that exercised about *how*.
>I spent 15 minutes last night trying to understand unittest well enough
>to import the various test cases in a doctest suite into a unittest, but
>no joy ;(.  I just don't understand the unittest magic very well, I'm
>afraid.  While I understand the distinction between a TestCase and a
>TestSuite, I can't understand why my unittest.TestCases run multiple
>(There's a reason I use nose: I've never understood unittest.)
>testing-in-python mailing list
>testing-in-python at lists.idyll.org

More information about the testing-in-python mailing list