[TIP] Best way to do setup/teardown on a per-test basis using doctest?
Titus Brown
titus at caltech.edu
Sun Jul 1 21:24:56 PDT 2007
-> >Short answer: I don't know. The setup/teardown part of doctests
-> >is, IMO, quite annoying. There was some mention a few months back on
-> >this list of using reST-style footnotes to specify setup and teardown
-> >code (related to Zope, I believe). That would be a good solution to
-> >try.
-> >
-> >Right now I would approach your problem by developing a utils module
-> >that contains functions to do the setup/teardown, and then I'd call
-> >them explicitly in the doctests.
->
-> But how do I guarantee that the teardown is called? If do something like::
->
-> """Here are some tests
-> >>> with setup():
-> ... test1
-> ... test2
->
-> """
->
-> That won't test anything from my understanding of doctest as that
-> would be executed as a single statement and not a bunch of indivudal
-> expressions to verify the output.
->
-> This just might be a situation where unittest is just a better fit.
You might be right. I wonder if the zope doctest guarantees that the
teardown is called?
--t
More information about the testing-in-python
mailing list