Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何仅使用pytest测试特定值?_Python_Pytest - Fatal编程技术网

Python 如何仅使用pytest测试特定值?

Python 如何仅使用pytest测试特定值?,python,pytest,Python,Pytest,我想知道如何通过pytest只测试某些值。我想执行的代码如下 导入pytest a=[1,2] b=[1,2,3] @pytest.fixture(参数=a) def返回_a(请求): 返回请求.param @pytest.夹具(参数=b) def返回_b(请求): 返回请求.param def测试(返回a、返回b): 如果返回值_a==1: 断言return\u a您必须重新参数化特定测试,以覆盖return\u a夹具的默认参数化。无法在每个测试中声明某种过滤器。间接参数化示例: # use

我想知道如何通过pytest只测试某些值。我想执行的代码如下

导入pytest
a=[1,2]
b=[1,2,3]
@pytest.fixture(参数=a)
def返回_a(请求):
返回请求.param
@pytest.夹具(参数=b)
def返回_b(请求):
返回请求.param
def测试(返回a、返回b):
如果返回值_a==1:

断言return\u a您必须重新参数化特定测试,以覆盖
return\u a
夹具的默认参数化。无法在每个测试中声明某种过滤器。间接参数化示例:

# use the default parametization in fixtures
def test_all(return_a, return_b):
    ...

# overwrite parametrization of `return_a`
@pytest.mark.parametrize("return_a", [1], indirect=True)
def test_some(return_a, return_b):
    ...