pythonpytest

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

  • 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.