mark中的skip:
场景:
- 调试时不执行此用例
- 标记无法在某平台上运行的测试功能
- 当前的外部资源不可用时跳过执行
- 某版本中执行,其他版本跳过
import pytest
class TestPytest:
# @pytest.mark.skip(reason="跳过测试")
@pytest.mark.skipif(1 == 2, reason="跳过测试")
def test_baidu(self):
print(6 * "=", "test_baidu", 6 * "=")
print("test_baidu 方法执行了。。。")
assert 1 == 1
mark中的xfail:
场景:
import pytest
class TestPytest:
def test_smoke(self):
print(6*"=", "smoke", 6*"=")
pytest.xfail(reason="xfail reason")
print("test_smoke 方法执行了。。。")
assert 1 == 1
@pytest.mark.xfail
# @pytest.mark.xpass
def test_sina(self):
print(6*"=", "smoke", 6*"=")
print("test_sina 方法执行了。。。")
assert 1 == 1
自定义mark:
场景:
步骤:
- 项目根目录下新增pytest.ini文件
- 在pytest.ini文件中添加自定义标签
[pytest]
markers=
smoke:smoke
sina:sina
baidu:baidu
google:google
telnet:telnet
import pytest
class TestPytest:
@pytest.mark.smoke
def test_smoke(self):
print(6*"=", "smoke", 6*"=")
print("test_smoke 方法执行了。。。")
assert 1 == 1
执行:
- pytest -v -m smoke
- pytest -v -m "not smoke"
- pytest.main(["-s", "-m='not smoke'"])
网友评论