【问题标题】:py.test: Show local variables in Jenkinspy.test:在 Jenkins 中显示局部变量
【发布时间】:2017-12-06 12:20:59
【问题描述】:

到目前为止,我们通过 Jenkins 致电 py.test

如果测试失败,我们会看到像这样的通常堆栈跟踪

Traceback (most recent call last):
  File "/home/u/src/foo/bar/tests/test_x.py", line 36, in test_schema_migrations
    errors, out))
AssertionError: Unknown output: ["Migrations for 'blue':", ...] 

如果我能在 django 调试页面中看到局部变量(参见 https://djangobook.com/wp-content/uploads/figure2_3a.png),那就太好了。

....但只有当我想看到它们时它们才应该可见。我想这意味着我需要与文本不同的格式。也许是 HTML?

有没有办法启用它?

我从未使用过 Sentry 工具。但是 AFAIK 这可以显示带有局部变量的很好的回溯。

【问题讨论】:

  • moidule cgitb 可以帮忙 - 在模块顶部插入 cgitb.enable(format='text', context=12)
  • @CharlesPehlivanian 是的,这可以工作。但这会使默认印象膨胀。我只想有时查看局部变量。如果我总是看到他们,那么日常工作就会变得更加困难......
  • 喜欢在 djangobook 页面上使用下拉菜单吗?纯文本不行,不知道有什么这样的服务……
  • @CharlesPehlivanian 你称之为“服务”。我认为您需要两部分:一部分创建带有更详细信息的回溯,另一部分将其呈现为 HTML。
  • 没试过这个,但cgitb.enable(format='html') 可能会给你你想要的。试一试。

标签: python django jenkins pytest sentry


【解决方案1】:

使用-l/--showlocals 选项:

pytest --showlocals # show local variables in tracebacks
pytest -l           # show local variables (shortcut)

示例:

    def foo():
        a = 1
>       assert 0
E       assert 0

a          = 1

test_foo.py:8: AssertionError

more details in the doc

【讨论】:

  • 我只想偶尔查看局部变量。如果我总是看到他们,那么每天的工作就会变得有点困难..
  • 好的,但是我的所有 CI 都有这个选项,这非常有用。
  • @guettli,可以捕获也可以不捕获。有时在运行测试之前不更改一些配置如何定义?
猜你喜欢
  • 1970-01-01
  • 2017-09-17
  • 2015-02-11
  • 2019-03-01
  • 1970-01-01
  • 2020-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多