Skip to content

Add an ability to print line number or stack trace of the failing assert in unit tests in Starlark #13275

@hlopko

Description

@hlopko

Hello dear Bazel maintainers :)

I'm re-filing this feature request from bazelbuild/bazel-skylib#290.

Right now there is not a way to print an assertion failure with the stack trace. We currently print the assertion error with the location .../external/bazel_skylib/lib/unittest.bzl:351:10:. It would be much more useful if we either printed the entire stack trace, or show the location of the callsite.

An argument could be made that there should be just one assertion per unit test, in that scenario this is not a problem. However there is so much boilerplate involved with adding a unit test that this is not practical to have one assertion per test. And even Bazel's internal BuildViewTestCase tests have multiple assertions per test.

@tetromino suggested to add something like a stacktrace() builtin or perhaps a with_stacktrace optional named parameter to print(). Both sound good to me.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4This is either out of scope or we don't have bandwidth to review a PR. (No assignee)not staleIssues or PRs that are inactive but not considered staleteam-Starlark-IntegrationIssues involving Bazel's integration with Starlark, excluding builtin symbolstype: feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions