小编mve*_*lay的帖子

如何使用params上的自定义标记在pytest中选择测试子集

我想知道如何使用pytest自定义标记选择我的测试子集

一个简单的测试按预期工作:

带有一个标记参数的代码

import pytest

@pytest.mark.parametrize('a', [pytest.mark.my_custom_marker(0), 1])
@pytest.mark.parametrize('b', [0, 1])
def test_increment(a, b):
    pass
Run Code Online (Sandbox Code Playgroud)

如果我只想运行标有'my_custom_marker'的测试

产量

$ pytest test_machin.py -m my_custom_marker --collect-only
platform linux2 -- Python 2.7.12, pytest-3.0.5, py-1.4.32, pluggy-0.4.0
rootdir: /home/mvelay/workspace/sandbox, inifile: 
plugins: hypothesis-3.6.0, html-1.12.0, xdist-1.15.0, timeout-1.0.0
collected 4 items 
<Module 'test_machin.py'>
  <Function 'test_increment[0-0]'>
  <Function 'test_increment[0-1]'>
Run Code Online (Sandbox Code Playgroud)

但是一旦我尝试测试多个标记的参数,我就会面临一个问题

代码带有两个标记的参数

import pytest

@pytest.mark.parametrize('a', [pytest.mark.my_custom_marker(0), 1])
@pytest.mark.parametrize('b', [pytest.mark.my_custom_marker(0), 1])
def test_increment(a, b):
    pass
Run Code Online (Sandbox Code Playgroud)

产量

$ pytest -m my_custom_marker test_machin.py --collect-only
platform linux2 -- Python 2.7.12, pytest-3.0.5, py-1.4.32, pluggy-0.4.0
rootdir: /home/mvelay/workspace/sandbox, inifile: …
Run Code Online (Sandbox Code Playgroud)

python pytest python-2.7

5
推荐指数
1
解决办法
1882
查看次数

标签 统计

pytest ×1

python ×1

python-2.7 ×1