'How to import SubRequest (pytest)?

In the following code, the request has the type of <class '_pytest.fixtures.SubRequest'>. I want to add type hint to the parameter request.

@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")

The following import doesn't work.

from pytest.fixtures import SubRequest


Solution 1:[1]

I've found one on the internet, hope this will help.

from _pytest.fixtures import SubRequest

I think it's worth trying, but not sure whether it could work, sorry.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yongle Liu