Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read custom config from pytest.ini?

Tags:

python

pytest

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
like image 727
pr4bh4sh Avatar asked Apr 11 '16 14:04

pr4bh4sh


1 Answers

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')
like image 122
The Compiler Avatar answered Nov 16 '22 12:11

The Compiler