2016-04-11 6 views
1

私はpytest.iniファイルにカスタムパラメータを提供し、コードからそれを読みたいと思っています。ここ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をスローしていない:

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

ドキュメントを読んでチェックする私はそれがカスタム値をサポートしているとは思っていませんconfig https://pytest.org/latest/customize.html – lapinkoira

+0

@ lapinkoiraこれは、iniファイルが 'Builtin設定ファイルオプション '[(link)](https://docs.pytest.org/ja/latest/customize.html#builtin-configuration-file-options)開発者は任意のオプションを生成する手段を残さないでしょうか?条件付きで拡張テストと基本テストを実行するオプションを作成し、自家製の環境変数チェックなどの代わりに組み込みのものを探していました。 – jxramos

答えて

2

「custom_value」という名前のオプションはあなたが使用する必要はありませんよpytest_addoptionオプションを知らせるフック:

def pytest_addoption(parser): 
    parser.addini('custom_value', 'documentation of my custom value') 
関連する問題