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_springboo
Solution 1:
You should really look at pytest-dependency plugin: https://pytest-dependency.readthedocs.io/en/latest/usage.html
import pytest
@pytest.mark.dependency()deftest_b():
pass@pytest.mark.dependency(depends=["test_b"])deftest_d():
pass
in this example test_d won't be executed if test_b fails
Solution 2:
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
Solution 3:
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 ======================
Post a Comment for "Pytest Skip Everything If One Test Fails"