Python unittest, running only the tests that failed

Viewed 1575

I have a large python test file using unittest that I run from the command line. Some tests take a while to run. This is a mild pain point because I'm often only concerned with the last test I added. What I want is this:

  1. add test.
  2. run tests (one fails because I haven't written the code to make it pass)
  3. implement the behaviour
  4. run only the test that failed last time
  5. fix the silly error I made when implementing the code
  6. run only the failing test, which passes this time
  7. run all the tests to find out what I broke.

Is it possible to do this from the command line?

3 Answers

Just run the test with --last-failed option (you might need pytest)

Related