首页 > 解决方案 > setup_class引发异常时如何跳过所有测试用例

问题描述

如果 setup_class 发生异常,有谁知道如何跳过测试套件?我有如下代码

import pytest
#@pytest.mark.skip(reason='skip if testsuite') #i can put skip here to skip all TestSuite
class TestSuite():
    @classmethod
    def setup_class(cls):
        try:
            raise Exception(f'can not find suitable strategy: {e}')
        except Exception as a:
            #I want to skip the testsuite for all testcase

    def test_func1(self):
        pass 
    def test_func2(self):
        pass 
    def test_func3(self):
        pass 

标签: pythonpython-3.xpytest

解决方案


http://doc.pytest.org/en/latest/skipping.html

你可以把它放在你的异常块中:

pytest.skip("failed to complete setup")

推荐阅读