[py-dev] How to re-run just failed tests

Krzysztof Kowalczyk kkowalczyk at gmail.com
Tue Jan 4 05:24:08 CET 2005


I'm quite new to py.test and looking for some guidance. I have the
same problem with py.test as I had with built-in unittest module: I
can't seem find an easy way to re-run just the tests that failed.

Let's assume that you have a lot of tests and each of the tests takes
some time. Let's further assume that tests are independent and only
few tests fail. It would be most desired if there was a way to easily
re-run the tests that just failed. Otherwise, I have to re-run all the
tests after trying to fix the code for the failed tests, which is a
waste of time.

I know two work-arounds, but they don't meet the 'easy' criteria:
a) move the failing tests to a separate file and proceede as usual
b) write my own test logger which would save the failures from the
last run e.g. to a file and provide an option to just re-run those
tests. It could be as simple  as writing names of the tests that
failed to a file and then, if, say, -rerun-failed option is given to
py.test, only those tests are re-ran

Even though the option b) seems simple, I'm not sure if it's easy to implement.

Is some such functionality provided with py.test out-of-the-box, by
any chance? Or anything else, that migth meet my needs e.g. ability to
specify a list of test functions to run to py.test (as opposed to
executing them all)?

Krzysztof Kowalczyk | http://blog.kowalczyk.info



More information about the Pytest-dev mailing list