1.skip 跳过执行函数
语法
@pytest.mark.skip(reason=None) #reason非必填,跳过的原因示例
import pytest
@pytest.mark.skip(reason="还没实现这个功能")
def test_future_feature():
assert False
2.skip满足条件,则跳过
import sys
import pytest
@pytest.mark.skipif(sys.platform == "win32", reason="不支持 Windows 平台")
def test_only_linux():
assert True第一个参数:条件表达式(返回
True时跳过测试,False时执行测试)。reason:必须写,说明为什么跳过。
3.自定义@pytest.mark.skip()标签
import pytest
myskip = pytest.mark.skip(reason="跳过这个")
@myskip
def test_only_linux():
assert True4.通过pytest.skip()方法跳过测试函数
import pytest
def test_only_linux():
pytest.skip(reason="only linux")
assert True5.跳过测试类
import pytest
@pytest.mark.skip(reason="这个类的测试暂时不跑")
class TestExample:
def test_one(self):
assert 1 == 1
def test_two(self):
assert 2 == 2
6.跳过模块
import pytest
pytestmark = pytest.mark.skip(reason="这个模块的测试都跳过")
def test_one():
assert 1 == 1
def test_two():
assert 2 == 2
