Python 3.x 在所有测试中自动注入对象,或从pytest中的夹具中自动注入测试类
我想在装置中初始化http包装器类。该夹具将用于所有测试。是否可以自动插入所有测试,以便执行以下操作: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
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_包装器。我知道所有的测试都会用到它