python - py.test : Show local variables in Jenkins

标签 python django jenkins pytest sentry

到目前为止,我们通过 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 这个工具。但是据我所知,这可以显示带有局部变量的很好的回溯。

最佳答案

使用-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 .

关于python - py.test : Show local variables in Jenkins,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47674185/

相关文章:

python - 如何限制 Django admin 中的选择数量

sql - 在 Django 查询中提供一个 LIMIT 参数而不需要获取 QuerySet 的一部分

java - 错误java.lang.NoSuchMethodError : No such DSL method '***' found among steps

linux - 如何自动将代码从本地存储库推送到远程 bitbucket 存储库?

python - WordPress Api 请求错误 : [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl. c:700)

python - 使用包在多个模块之间拆分 Python 类

python - 元素在模态窗口中不可见 - Selenium Python

python - 是否可以获取用于评估 xpath 结果的所有上下文节点?

Django 最佳实践 : number of model classes per file/directory structure

python - winexe执行make时出错