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

James Bohnert skilletaudio at gmail.com
Mon Jan 30 14:42:12 PST 2012


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?

Thank you kindly,
James



More information about the testing-in-python mailing list