目前,当我的一个测试失败时,它会打印出单元测试的参数,后跟堆栈跟踪。但是,如果参数是大型JSON对象,则不显示完整对象。有没有一种方法可以很容易地强制执行py.测试不切断数据?堆栈跟踪示例:
TestSpecialOfferDefaultContentUser.test_check_default_content_for_user[test_data0]
self = <scripts.spof.test_01_special_offer_default_content_user.TestSpecialOfferDefaultContentUser instance at 0x00000000022CF8C8>
config = <merlin.lib.configuration_test.TestConfiguration object at 0x00000000022DD1D0>
test_data = {'amount_of_number_of_days_options': 6, 'available_for_guest': 'True', 'fl_password': 'password', 'fl_user': 'gg_abrestest@yahoo.com', ...}
@pytest.mark.parametrize("test_data", _test_cases_special_offer)
def test_check_default_content_for_user(self, config, test_data):
[...]
好问题。在
找不到命令行开关来强制完成打印输出
在搜索和测试
py.test
的各种命令行选项时,我没有找到任何方法来获得完整的 字典打印输出。在这可能是有充分理由的,无休止的打印输出不是很有用。在
使用assert message获取您自己的打印输出
虽然
py.test
在解释错误的有用消息方面做得很好,但有时您必须自己动手。在assert
具有带消息的可选参数。如果您使用它,py.test
打印输出将被您放入该消息中的内容替换。在拥有文件
test_it.py
:你可以试试:
^{pr2}$你会看到:
你是对的,目前这无法显示,这可能是一个功能请求,所以请提交一个错误。在
然而,解决这个问题的“标准”方法是简单地依赖py.测试的优秀输出捕获功能,并在测试期间显式打印参数:
这将导致信息在rest故障报告中可用。在
相关问题 更多 >
编程相关推荐