[英]Add logs in junit xml from pytest_generate_tests method
我正在使用 Jenkins 來解析 Junit XML。 任何開發人員也會查看 Jenkins 故障以進行分類。 這意味着所有日志都應該在 Junit xml 中可用。
問題是方法 pytest_generate_tests 有一個非常大的實現,並且需要日志消息來進行故障排除。
但是,pytest_generate_tests 中添加的日志消息並沒有出現在 Junit xml 中。 如果測試發現失敗,有沒有辦法在 Junit xml 中包含日志消息?
我提供的命令
pytest -vv --log-level=INFO --junit-xml=sample.xml
pytest.ini(添加了 junit_logging 希望 Junit_xml 包含日志)
[pytest]
junit_logging = all
我的樣本 Junit.xml (沒有任何與 pytest_generate_tests 相關的日志)
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite errors="1" failures="0" hostname="W117-JayJ" name="pytest" skipped="0" tests="1" time="0.960" timestamp="2020-04-12T10:27:31.178617">
<testcase classname="tests.test_my_addon" file="tests/test_my_addon.py" name="Test_App" time="0.000"><error message="collection failure">pyparallel\lib\site-packages\pluggy\hooks.py:286: in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs
. . . a Big stack trace . . .
raise Exception("This is a random Failure ")
E Exception: This is a random Failure </error>
</testcase>
</testsuite>
</testsuites>
Junit xml 中沒有附加日志消息。
我可以在“收集...”后查看控制台中的日志
========================================================================================== test session starts ==========================================================================================
platform win32 -- Python 3.7.4, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
rootdir: C:\Jay\Work\Automation\pytest-sample-addon\new_dev_environment, inifile: pytest.ini, testpaths: tests
plugins: lovely-pytest-docker-0.1.0, forked-1.1.3, xdist-1.31.0, sample-addon-0.1.0
collecting ... generating testcases for app. fixture=app_positive_cases
generating field tests..
collected 0 items / 1 error
有沒有辦法在控制台中正確處理日志並將其添加到 Junit.xml 中?
通過嘗試,我在類似情況下取得了一些成功:
junit_logging = system-out
全部嘗試都沒有用,但系統輸出確實有效。 試試這個,看看它是否產生日志。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.