long running py.test stop at first failure

Matt picture Matt · Apr 23, 2016 · Viewed 19k times · Source

I am using pytest, and the test execution is supposed to run until it encounters an exception. If the test never encounters an exception it should continue running for the rest of time or until I send it a SIGINT/SIGTERM.

Is there a programmatic way to tell pytest to stop running on the first failure as opposed to having to do this at the command line?

Answer

Praveen Yalagandula picture Praveen Yalagandula · Apr 23, 2016
pytest -x             # stop after first failure
pytest --maxfail=2    # stop after two failures

See the documentation at http://pytest.org/en/latest/usage.html