Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import SubRequest (pytest)?

Tags:

python

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
like image 258
ca9163d9 Avatar asked Feb 22 '26 05:02

ca9163d9


1 Answers

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.

like image 68
Richard Avatar answered Feb 24 '26 17:02

Richard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!