テストスイートの各テストケースには、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-html
のextras
属性でパラメータを追加することにより、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
属性を得ることができますか?
いくつかの調査結果 -
junitxml
がextras
record_xml_property
を持っていない私はそれがテストの機能ですとしてそれを使用する必要はありません。また、デコレータで複数の引数を追加すると、素晴らしいアプローチのように見えます。私はコードの読みやすさを妨げたくありません。def test_function(record_xml_property): record_xml_property("key", "value") assert 0
次のアプローチ
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
オブジェクトを手に入れることができませんでしたそれ。 ので
、それはおおよそ次のようになりますように、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>