[py-dev] feedback on py.test discovery/setup/process documentation

Jason R. Coombs jaraco at jaraco.com
Thu Aug 5 17:05:49 CEST 2010


I was espousing the joys of py.test at a recent #DCPython meetup. I found,
however, that I'm not the only person frustrated by the lack of
documentation on the basic process py.test uses to discover, setup, and
conduct tests.

 

There's mention here and there of setup/teardown methods, and their names
are fairly intuitive, but I can't find that they're documented anywhere. It
would be nice if there was a half-page document on the process py.test uses
to conduct a single test. something like:

 

# globally

Run pytest_configure

For each test module matching test_*.py:

                Run setup_module(module object)

                For each class in module.Test*:

                                skip if it's not a valid test class (i.e.
has an __init__ method)

                                Run setup_class(class_object) [p.s. why
doesn't setup_class have to be a classmethod?]

                                For each method:

                                                Run setup_method(instance,
method)

                                                Run test

                                                Run teardown_method

                                Run teardown_class

.

 

I've discovered all of this through trial and error (and tracking down
examples here and there). For example, I couldn't find setup_method
documented anywhere, even though I knew what I wanted (a setup for each test
to be run).

 

Also, it would be nice to have some clarification on which classes will be
discovered. I was recently bitten by an interesting feature. If a test class
has an __init__ method, it will not be run as a test. For one test, I was
using the __init__ method to define setup for each instance of the test. It
turns out that by using setup_method instead of __init__, it did precisely
what I wanted, but I went several weeks thinking my tests were running, when
they were being silently skipped.

 

I realize that all of this seems a little nitpicky. Truly, I love py.test,
but I have to agree with my colleagues that it's a little difficult getting
to know the basics. It doesn't help matters that because of the name, it's
difficult to search the web for py.test resources.

 

If you have any suggestions on how I might have learned these details other
than through trial-and-error, please point me to them.

 

Regards,

 

Jason

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20100805/186450b0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 6448 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20100805/186450b0/attachment.bin>


More information about the Pytest-dev mailing list