[TIP] Some simple examples for testing stuff
C. Titus Brown
ctb at msu.edu
Wed Mar 10 13:50:32 PST 2010
On Wed, Mar 10, 2010 at 01:48:28PM +0000, Michael Foord wrote:
> On 09/03/2010 06:12, C. Titus Brown wrote:
>> An example of using 'discover':
> Hi Titus,
> As I said to you in a private email, but perhaps it bears discussing
> here, test discovery (unittest2 or the discover module) doesn't
> automatically look in package files (__init__.py) by default.
> That's actually the expected (by me) and documented behaviour - although
> whether it is correct or not is debatable, and I'm open to discussion on
> the subject.
I guess I was confused by this paragraph in the docs at http://pypi.python.org/pypi/discover/0.3.2:
If a test package name (directory with __init__.py) matches the pattern then
the package will be checked for a load_tests function. If this exists then it
will be called with loader, tests, pattern.
I interpreted that to mean "if a test package name matches the *test* pattern
then..." which apparently it does not?
> Part of the reason for it is my distaste for putting anything
> (especially tests) in your __init__.py. It is also relatively common
> practise to explicitly import your tests from sub-modules into the
> package level __init__ - so that custom collection code only need import
> them from the package and not have to visit all the submodules. Where
> this is the case, visiting the package as well as the sub-modules in
> discovery by default would find every test *twice*.
Good point; I was just confused by the docs.
More information about the testing-in-python