Reputation: 3529
What is best way to skip every remaining test if a specific test fails, here test_002_wips_online.py failed, and then there is no point in running further:
tests/test_001_springboot_monitor.py::TestClass::test_service_monitor[TEST12] PASSED [ 2%]
tests/test_002_wips_online.py::TestClass::test01_online[TEST12] FAILED [ 4%]
tests/test_003_idpro_test_api.py::TestClass::test01_testapi_present[TEST12] PASSED [ 6%]
I like to skip all remaining tests and write test report. Should I write to a status file and write a function that checks it?
@pytest.mark.skipif(setup_failed(), reason="requirements failed")
Upvotes: 2
Views: 3132
Reputation: 574
You should really look at pytest-dependency plugin: https://pytest-dependency.readthedocs.io/en/latest/usage.html
import pytest
@pytest.mark.dependency()
def test_b():
pass
@pytest.mark.dependency(depends=["test_b"])
def test_d():
pass
in this example test_d
won't be executed if test_b
fails
Upvotes: 4
Reputation: 3529
I found that calling pytest.exit("error message")
if any of my critical predefine tests fail is the most convenient. pytest will finish all post jobs like html-report, screenshots and your error message will be printed at the end:
!!!!!!!!!!! _pytest.outcomes.Exit: Critical Error: wips frontend in test1 not running !!!!!!!!!!!
===================== 1 failed, 8 passed in 92.72 seconds ======================
Upvotes: 0
Reputation: 60604
from the docs: http://pytest.org/en/latest/usage.html#stopping-after-the-first-or-n-failures
pytest -x # stop after first failure
pytest --maxfail=2 # stop after two failures
Upvotes: 3