[TIP] py.test, flagging remaining tests in a class/file as skip depending on preconditions

Ronny Pfannschmidt Ronny.Pfannschmidt at gmx.de
Mon Jan 30 15:03:49 PST 2012


Hi,

On 01/30/2012 11:42 PM, James Bohnert wrote:
> Working on a proof of concept for a testing structure with py.test
> 2.2.1 - I want to split up tests into different files covering
> different areas of a product, and probably use test classes to further
> organize within the files.
> 
> I would like to use some convention to establish a 'prerequisite' test
> case in each file or class, upon failure of which the rest of the
> tests in that class/file would be Skipped, but otherwise test
> collection and running continues as normal.  I really dont want to
> have to put conditionals with skips in every test case or other
> methods that would require boilerplate throughout the test cases.
> 
> It looks like the solution involves setting up the
> pytest_runtest_setup hook, and skip() on the testing of some value
> that would be toggled in the first test of the file/class (the
> 'prereq' test), but Im not sure if there is a nice way to flag the
> condition from inside one test, have it affect the remainder of a
> group of tests, but then cleanly reset on the next collection/class of
> tests.
> 
> Any pointers?
> 
you could use marks to mark prerequisite tests at the wanted scope
(class/module)
and always run those, while running normal tests only if all
prerequisites for the scope have executed first and passed

there may be implications wrt test ordering,
but i wont think about the details tonight

cheers,
Ronny

> Thank you kindly,
> James
> 
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 900 bytes
Desc: OpenPGP digital signature
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20120131/0a03521d/attachment.pgp>


More information about the testing-in-python mailing list