Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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 3.x 在所有测试中自动注入对象,或从pytest中的夹具中自动注入测试类_Python 3.x_Pytest - Fatal编程技术网

Python 3.x 在所有测试中自动注入对象,或从pytest中的夹具中自动注入测试类

Python 3.x 在所有测试中自动注入对象,或从pytest中的夹具中自动注入测试类,python-3.x,pytest,Python 3.x,Pytest,我想在装置中初始化http包装器类。该夹具将用于所有测试。是否可以自动插入所有测试,以便执行以下操作: import pytest @pytest.fixture() def init_wrapper(): wrapper = HttpWrapper() 我希望在测试中自动执行包装器对象,而不在测试中传递fixture name作为参数 def test_something(): wrapper.get_call() def test_somthing1(): wrap

我想在装置中初始化http包装器类。该夹具将用于所有测试。是否可以自动插入所有测试,以便执行以下操作:

import pytest
@pytest.fixture()
def init_wrapper():
   wrapper = HttpWrapper()
我希望在测试中自动执行包装器对象,而不在测试中传递fixture name作为参数

def test_something():
    wrapper.get_call()

def test_somthing1():
    wrapper.post_call()
如果上面不可能,我可以将初始化包装器对象设置为TestClass的成员变量,以便将其用作

def test_something():
    self.wrapper.get_call()
原因是我不想在所有测试用例中传递init_包装器。我知道所有的测试都会用到它