有小伙伴提到能不能只收集用例失败的情况下日志和错误信息,每个用例都收集日志内容太多了,没法直观的看错误的用例信息。 v1.3.9 版本实现此功能,在原有的功能上新增一个log日志文件,仅收集用例错误的日志。
用例执行完会默认生成2个日志文件
使用示例
config:
name: demo
test_1:
name: 用例1
print: "111111"
test_2:
name: 用例2
print: "2222"
validate:
- eq: [200, 201]
用例执行后根据当前时间生成一个20230707_201045_error.log 日志文件
************************* a1/test_a2.yml::test_2 *************************
测试结果 outcome:failed
用例耗时 duration:0.003574687999999826
异常 exception:<ExceptionInfo AssertionError("200-><class 'int'> == 201-><class 'int'>\nassert 200 == 201") tblen=4>
exception详细日志:request = <FixtureRequest for <Function test_2>>
requests_session = <pytest_yaml_yoyo.http_session.HttpSession object at 0x0000022D4EF43D00>
> ???
test_a2.py:2:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv\lib\site-packages\pytest_yaml_yoyo\runner.py:222: in execute_yaml_case
self.validate_response(response, validate_value)
venv\lib\site-packages\pytest_yaml_yoyo\runner.py:559: in validate_response
validate.equals(actual_value, expect_value)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
check_value = 200, expect_value = 201
def equals(check_value, expect_value):
check_value = None if check_value == 'None' else check_value
expect_value = None if expect_value == 'None' else expect_value
> assert check_value == expect_value, f'{check_value}->{type(check_value)} == {expect_value}->{type(expect_value)}'
E AssertionError: 200-><class 'int'> == 201-><class 'int'>
E assert 200 == 201
venv\lib\site-packages\pytest_yaml_yoyo\validate.py:10: AssertionError
Captured stdout call2222
Captured log call[32mINFO [0m pytest_yaml_yoyo.log:runner.py:128 执行文件-> test_a2.yml
[32mINFO [0m pytest_yaml_yoyo.log:runner.py:129 base_url-> http://124.70.221.221:8201
[32mINFO [0m pytest_yaml_yoyo.log:runner.py:130 config variables-> {}
[32mINFO [0m pytest_yaml_yoyo.log:runner.py:132 运行用例-> test_2
[32mINFO [0m pytest_yaml_yoyo.log:runner.py:221 validate 校验内容-> [{'eq': [200, 201]}]
[32mINFO [0m pytest_yaml_yoyo.log:runner.py:557 validate 校验结果-> eq: [200, 201]
根据用例节点a1/test_a2.yml::test_2
详细记录用例报错的内容和用例运行的日志.