Mohd Faheem
Mohd Faheem

Reputation: 93

How to get the rootdir parameter value while executing pytest

After executing the pytest I could see its populating the rootdir in results based on the path of "pytest.ini". My issue is I need to use relative path to read some of the files as part of testing, so is there a way to fetch this "rootdir" parameter value during test execution

Upvotes: 4

Views: 3507

Answers (1)

hoefling
hoefling

Reputation: 66551

Use the request fixture. Example:

def test_ini(request):
    rootdir = request.config.rootdir
    assert (rootdir / 'pytest.ini').isfile()

Upvotes: 7

Related Questions