在pytest中防止长字符串被截断 [英] Preventing truncation of long strings in pytest

查看:169
本文介绍了在pytest中防止长字符串被截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个测试工具,用于使用pytest对我们的代码进行系统测试.这些测试在我们的持续集成系统中使用,因此我正在使用junit xml输出选项. pytest截断长字符串给我带来了问题.我知道我可以使用-vv选项阻止它,但是这样会使每个测试的结果产生冗长的输出,很难理解.从本质上讲,我想要一种至少在junit xml文件中防止长字符串被截断的方法.如果它也可以在控制台输出中使用,那会更好,但不是必需的.

I have written a test harness for system tests of our code using pytest. These tests are used in our continuous integration system so I am using the junit xml output option. The truncation of long strings by pytest is causing me problems. I know I can prevent it using the -vv option but then that gives verbose output for the results of each test which is difficult to read. Essentially I want a different way to prevent the truncation of the long string at least in the junit xml file. If it also worked in the console output, that would be better but not essential.

我们的代码生成带有大量值的报告,我将输出与一组已知正确的输出进行比较.我正在报告所有错误的字段,而不仅仅是第一个错误.所以我正在生成一个字符串列表,每个字符串有一个错误.然后,我用换行符将字符串连接在一起,以创建一个长字符串和包含所有错误的长字符串.如果断言失败,那么我需要查看字符串的整个内容,这可能是几百行.

Our code produces reports with a large number of values and I compare the output to a set of output known to be correct. I am reporting all fields that are in error not just the first error. So I am generating a list of strings with one error per string. I then join the strings with newlines to create one long string and long string that contains all the errors. If the assertion fails I need to see the entire contents of the string which could be several hundred lines.

errors = []
error.extend(get_report_errors())
s = '\n'.join(errors)
assert (s == '')

任何建议

我正在使用python 2.6和2.7和pytest 2.3.5.我可以升级所需的pytest版本.

I am using python 2.6 and 2.7 and pytest 2.3.5. I can upgrade the version of pytest of needed.

推荐答案

您可以使用tb标志,这是pytest的回溯输出. 有几种选择: --tb=style traceback print mode (auto/long/short/line/native/no)

You can use the tb flag this is the traceback output for pytest. There is a few options for that: --tb=style traceback print mode (auto/long/short/line/native/no)

您需要选择最适合自己的东西.

You need to chooise what is the best for you.

这篇关于在pytest中防止长字符串被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆