从pytest_generate_tests方法在JUnitXML中添加日志

2024-05-09 18:11:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在与Jenkins合作,Jenkins解析JUnitXML。任何开发人员都会查看Jenkins故障以进行分类。这意味着所有日志都应该以JUnitXML格式提供

问题在于pytest_generate_tests方法有一个非常大的实现,需要日志消息来进行故障排除

但是,pytest_generate_测试中添加的日志消息不会出现在Junit xml中。如果测试发现失败,有没有办法在JUnitXML中包含日志消息

我提供的命令

pytest -vv --log-level=INFO --junit-xml=sample.xml

ini(添加了junit_日志,希望junit_xml将包含日志)

[pytest]
junit_logging = all

我的示例Junit.xml(没有任何与pytest\u generate\u测试相关的日志)

<?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(&quot;This is a random Failure &quot;)
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


Tags: samplepyaddontestself消息pytesttests
1条回答
网友
1楼 · 发布于 2024-05-09 18:11:58

在类似的情况下,我通过尝试获得了一些成功:

junit_logging = system-out

尝试所有的方法都不管用,但系统失效了。试试这个,看看它是否会产生日志

相关问题 更多 >