Skip to content
Advertisement

pytest skip everything if one test fails

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")

pytest-skipif-reference

Advertisement

Answer

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

Advertisement