如何导入子请求(pytest)?

ca9*_*3d9 5 python pytest

在以下代码中,请求的类型为<class '_pytest.fixtures.SubRequest'>. 我想在参数请求中添加类型提示。

@pytest.fixture
def dlv_service(request: SubRequest):  # How to import SubRequest?
    print(type(request), request)
    filepath = pathlib.Path(request.node.fspath.strpath)
    f = filepath.with_name("file.json")
Run Code Online (Sandbox Code Playgroud)

以下导入不起作用。

from pytest.fixtures import SubRequest
Run Code Online (Sandbox Code Playgroud)

小智 5

我在网上找到了一个,希望对你有帮助。

from _pytest.fixtures import SubRequest
Run Code Online (Sandbox Code Playgroud)

我认为值得尝试,但不确定是否可行,抱歉。