如何从pytest.ini读取自定义配置?

时间:2016-04-11 14:08:25

标签: python pytest

我想在pytest.ini文件中提供自定义参数,并从代码中读取它。

[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

这里我想阅读 custom_value 我在下面尝试了但它没有工作并抛出 ValueError:没有名为' custom_value'

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

1 个答案:

答案 0 :(得分:2)

您需要使用find('.text-angular div[contenteditable]').set('Upgraded to SSD') 挂钩来宣传该选项:

pytest_addoption