前言
pytest 使用 parametrize 参数化的时候,有多组测试数据,需要对其中的一些测试数据加标记跳过,可以用pytest.param实现。
pytest.param
先看下 pytest.param 源码,可以传三个参数
- param values :按顺序传参数集值的变量args
- keyword marks : marks关键字参数,要应用于此参数集的单个标记或标记列表。
- keyword str id: id字符串关键字参数,测试用例的id属性
def param(*values, **kw):
"""Specify a parameter in `pytest.mark.parametrize`_ calls or
:ref:`parametrized fixtures <fixture-parametrize-marks>`.
.. code-block:: python
@pytest.mark.parametrize("test_input,expected", [
("3+5", 8),
pytest.param("6*9", 42, marks=pytest.mark.xfail),
])
def test_eval(test_input, expected):
assert eval(test_input) == expected
:param values: variable args of the values of the parameter set, in order.
:keyword m