【问题标题】:Is there a way to see exception message in unit test during unit test?有没有办法在单元测试期间查看单元测试中的异常消息?
【发布时间】:2015-07-24 09:28:49
【问题描述】:

当我在测试中得到 500 个状态码而不是 200 个时

   responce = requests.post(url)
   self.assertEqual(responce.status_code, 200)

我在控制台中看到此消息

self.assertEqual(responce.status_code, 200)
AssertionError: 500 != 200

一切都很好,但我想了解更多关于实际情况的信息。 我的意思是 django 异常,例如 ViewDoesNotExist 或出现在调试页面中的其他类型的 django 异常。 我可以在测试过程中以某种方式将这些信息放在我的终端中吗?

【问题讨论】:

  • 如果你想测试你的视图和模板,你应该使用Client

标签: django unit-testing python-unittest


【解决方案1】:

我是这样解决的

    try:
        outdata = json.loads(responce.content)
    except Exception, err:  
        for par in re.findall('<pre class="exception_value">(.*?)<\/pre>',responce.content):
            print '#######%s######' % par

【讨论】:

    猜你喜欢
    • 2017-06-02
    • 2012-12-14
    • 2021-08-23
    • 2021-06-13
    • 1970-01-01
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多