2017-10-11 5 views
2

テストスイートの各テストケースには、XML(junit-xml)レポートに含める複数の属性が関連付けられています。 次のコードスニペットは、それに関する明確な画像を示しています。junitxml Pytestレポートをカスタムマーカーから複数の属性を追加するようにカスタマイズする

@data(*get_csv_data("csv/blah.csv")) 
@unpack 
@pytest.mark.run(order=70) 
@pytest.mark.webtest.with_args(jira="QA5555", second="second_arg_add") 
def test_your_stuff(self,arg1, arg2): 
    # Actual Test 

レポートをカスタマイズするが、以下に示すように、pytest-htmlextras属性でパラメータを追加することにより、pytest-htmlプラグインの属性を追加するのは簡単です。 conftest.py

@pytest.mark.hookwrapper 
def pytest_runtest_makereport(item, call): 
    pytest_html = item.config.pluginmanager.getplugin('html') 
    outcome = yield 
    report = outcome.get_result() 
    extra = getattr(report, 'extra', []) 
    if report.when == 'call': 
    extra.append(pytest_html.extras.text("<blah>") 
    report.extra = extra 

また、私は簡単に私がjunitxmlために同じことを行うことができますどのように

item.keywords.get('webtest').kwargs 

属性を得ることができますか?

いくつかの調査結果 -

  1. junitxmlextras
  2. record_xml_propertyを持っていない私はそれがテストの機能ですとしてそれを使用する必要はありません。また、デコレータで複数の引数を追加すると、素晴らしいアプローチのように見えます。私はコードの読みやすさを妨げたくありません。

    def test_function(record_xml_property): 
        record_xml_property("key", "value") 
        assert 0 
    
  3. 次のアプローチ

    if hasattr(request.config, "_xml"): 
    request.config._xml.add_custom_property(name, value) 
    

    私は順番に関連付けられたメソッドadd_custom_propertyを持っていないjunit-xmlにフックでここLogXMLからdef pytest_runtest_makereport(item, call): item.config._xmlポイントをrequestオブジェクトを手に入れることができませんでしたそれ。

  4. ので

、それはおおよそ次のようになりますように、junitxmlに多くの属性を追加するための最良の方法だろう何 -

<testcase classname="test_function" file="test_function.py" line="0" name="test_function" time="0.0009"> 
    <properties> 
    <property name="jira" value="1234566" /> 
    </properties> 
</testcase> 

またはそのため、この

<testcase classname="test_function" file="test_function.py" line="0" name="test_function" time="0.0009" jira="2345667"> 
</testcase> 

答えて

0

などをこれを達成するための簡単な方法がないように見えます。現在はpytestによってサポートされていません。これは現在feature requestというラベルが付けられています。

関連する問題