2

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

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

This will be perfect if I can get it to work on a session based fixture
hmm...will this solution help? stackoverflow.com/questions/46671567/…
3

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 

1 Comment

This case have around 50 tests, but only the first 5-6 test requirements and should skip everything if any fails. but the rest are independent and should be completed.
0

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 ====================== 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.