doctest, unittest, or if __name__='__main__'
bdesth.quelquechose at free.quelquepart.fr
Wed Mar 22 01:47:36 CET 2006
john_sips_tea at yahoo.com a écrit :
> For writing testcode, it looks like there's three ways that it's
> typically done:
Actually, there's at least one more
> (1). using the doctest module,
> (2). using the unittest module (i.e. "pyunit"), or else
> (3). just putting an "if __name__ = '__main__':" at the bottom of your
> module containing code to manually run your class through its paces.
(4) using pytest
> So, which way is preferred? Seems to me that unittest is the way to go,
> at least because it has you separate your test code from the code being
Which may or may not be such a good thing... I prefer to have my tests
with the code they're testing.
> If unittest is the standard way to write test code, why do we still
> have doctest?
Because doctest is simple, great, and definitively more pythonic than
> (I notice there's no mention in PEP 3000 of deprecating
> the doctest module).
More information about the Python-list