Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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_Unit Testing_Pytest - Fatal编程技术网

Python 使用pytest为装置提供默认参数化

Python 使用pytest为装置提供默认参数化,python,unit-testing,pytest,Python,Unit Testing,Pytest,我不想为一系列测试参数化同一组参数 无论何时使用夹具,我都希望使用“默认参数化”。那些“默认参数化”意味着代码中更少的@pytest.mark.parametrize 在某些情况下,将测试分组到一个类中并将整个测试类参数化可能会有所帮助。但我有几个固定装置的组合 如何将“默认参数化”设置为装置?某些装置是具有多个参数的类 我目前的解决方案很乏味: 导入pytest 进口itertools A类: 定义初始化(self,x,y): self.x=x self.y=y def big_data()

我不想为一系列测试参数化同一组参数

  • 无论何时使用夹具,我都希望使用“默认参数化”。那些“默认参数化”意味着代码中更少的
    @pytest.mark.parametrize

  • 在某些情况下,将测试分组到一个类中并将整个测试类参数化可能会有所帮助。但我有几个固定装置的组合

  • 如何将“默认参数化”设置为装置?某些装置是具有多个参数的类

    我目前的解决方案很乏味:

    导入pytest
    进口itertools
    A类:
    定义初始化(self,x,y):
    self.x=x
    self.y=y
    def big_data():
    返回[1,2,3]
    @pytest.fixture(
    params=itertools.product(big_data(),[True,False])
    )
    def a(请求):
    返回(*request.param)
    def测试_1(a):
    整数(a.x+a.y)
    @pytest.mark.parametize(“v”[10100])
    def测试_2(a,v):
    断言(a.x
    也许我可以为prameter的每个参数化使用一个基类。然后,我可以创建一个类X,它通过多重继承表示参数组合的参数化。类X中定义的所有测试都将具有我想要的参数化。但这太疯狂了。元函数的作用是: