pytest has the option -x or --exitfirst which stops the execution of the tests instanly on first error or failed test.
pytest also has the option --maxfail=num in which num indicates the number of errors or failures required to stop the execution of the tests.
pytest -x # if 1 error or a test fails, test execution stops
pytest --exitfirst # equivalent to previous command
pytest --maxfail=2 # if 2 errors or failing tests, test execution stops