Python 如何从pytest.ini读取自定义配置?
我想在pytest.ini文件上提供自定义参数,并从代码中读取它Python 如何从pytest.ini读取自定义配置?,python,pytest,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 在这里,我想阅读自定义值 我在下面尝试过,但不起作用,并抛
[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
在这里,我想阅读自定义值
我在下面尝试过,但不起作用,并抛出ValueError:没有名为“custom\u value”的选项。
def test_failtest(self, request):
config = request.config
tcv = config.getoption('custom_value')
print "tcv->" + tcv
您需要使用
pytest\u addoption
hook来显示选项:
def pytest_addoption(parser):
parser.addini('custom_value', 'documentation of my custom value')
阅读文档并检查源代码我认为它不支持config@lapinkoira中的自定义值,也就是说ini文件只支持为任何
内置配置文件选项设置有效值
,开发者无法生成任意选项?我希望创建一个选项来有条件地运行扩展测试,而不是基本测试,并且我正在寻找内置的东西,而不是自制的环境变量检查或类似的东西。