【发布时间】:2019-12-18 16:44:39
【问题描述】:
我有一个测试套件,它是一个类,每个测试方法都是一个测试用例。我还为每种方法(测试用例)提供了一个固定装置,它可以做一些基本的事情。我有一个奇怪的要求,如果 testfixture 失败,我想跳过测试套件中的所有测试用例。
以下是我拥有的示例套件
class TestFeature:
@pytest.fixture(scope="function", autouse=True)
def _wrapper(self):
print("Some precomditions")
yield
print("some post conditions")
def test_first_testcase(self):
print("First testcas")
def test_second_testcase(self):
print("second testcas")
def test_third_testcase(self):
print("Third testcas")
现在我想如果我的夹具失败,我想中止这个测试套件。假设我的第一个测试用例失败了。下一个测试用例的夹具失败。我想中止套件并且不想执行第三个测试用例。
如何在 pytest 中做到这一点
【问题讨论】: