为了账号安全,请及时绑定邮箱和手机立即绑定

如何为 pytest 命令指定多个标记

如何为 pytest 命令指定多个标记

Smart猫小萌 2022-09-06 19:43:41
阅读 http://doc.pytest.org/en/latest/example/markers.html 我看到基于标记包含或排除某些python测试的示例。包括:pytest -v -m webtest以外:pytest -v -m "not webtest"如果我想为包含和排除指定多个标记,该怎么办?
查看完整描述

1 回答

?
一只萌萌小番薯

TA贡献1795条经验 获得超7个赞

使用 / 组合多个标记,与选择器相同。示例测试套件:andor-k


import pytest



@pytest.mark.foo

def test_spam():

    assert True



@pytest.mark.foo

def test_spam2():

    assert True



@pytest.mark.bar

def test_eggs():

    assert True



@pytest.mark.foo

@pytest.mark.bar

def test_eggs2():

    assert True



def test_bacon():

    assert True

选择所有标记为“用”和“未用”标记的测试foobar


$ pytest -q --collect-only -m "foo and not bar"

test_mod.py::test_spam

test_mod.py::test_spam2

选择所有既不标记为 with 也不标有foobar


$ pytest -q --collect-only -m "not foo and not bar"

test_mod.py::test_bacon

选择标有 任一项的测试,foobar


$ pytest -q --collect-only -m "foo or bar"

test_mod.py::test_spam

test_mod.py::test_spam2

test_mod.py::test_eggs

test_mod.py::test_eggs2


查看完整回答
反对 回复 2022-09-06
  • 1 回答
  • 0 关注
  • 222 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号