pr4bh4sh
pr4bh4sh

Reputation: 714

How to read custom config from pytest.ini?

I want to provide custom parameters on the pytest.ini file and read it from code.

[pytest]
markers =
    regression: mark a test as regression.
    sanity: mark a test as sanity.
    critical: mark a test as critical.
addopts= -sv --html=report.html
custom_value= test

here i want to read custom_value I have tried below but it's not working and throws ValueError: no option named 'custom_value'

def test_failtest(self, request):
    config = request.config
    tcv = config.getoption('custom_value')
    print "tcv->" + tcv

Upvotes: 6

Views: 7899

Answers (1)

The Compiler
The Compiler

Reputation: 11969

You'll need to use the pytest_addoption hook to make the option known:

def pytest_addoption(parser):
    parser.addini('custom_value', 'documentation of my custom value')

Upvotes: 7

Related Questions