如何创建接受参数的新pytest命令行标志
例如,我有以下几点:
test_A.py::test_a
@pytest.mark.lvl1
def test_a():...
.
.
.
test_B.py::test_b
@pytest.mark.lvl10
def test_b():...
test_C.py::test_c
@pytest.mark.lvl20
def test_c():...
在命令行上,我只想运行标记级别小于等于lvl10的测试(因此lvl1到lvl10测试)
我如何做到这一点而不必在命令行pytest上手动键入-m'lvl1或lvl2或lvl3…'
我想创建一个新的命令行pytest arg,如: pytest--lte=“lvl10”(lte小于等于)
我在想,我想定义--lte标志来执行以下操作:
markers =[]
执行pytest collect以查找包含“lvl”标记的所有测试,并且仅当“lvl”后的整数小于等于10(lvl10)时,才将该标记添加到标记列表中。然后在标记列表上调用pytest-m('lvl1或lvl2或lvl3…')
如果修改标记以接受级别作为参数,则可以通过向conftest.py添加自定义
pytest_runtest_setup
来运行小于或等于指定级别的所有测试样本测试
conftest.py
示例调用
相关问题 更多 >
编程相关推荐