Add an ability to print line number or stack trace of the failing assert in unit tests in Starlark
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 75
Description
Hello dear Bazel maintainers :)
I'm re-filing this feature request from https://github.com/bazelbuild/bazel-skylib/issues/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!
Contributor guide
Research direction
Start with the assertion handling around external/bazel_skylib/lib/unittest.bzl:351:10 and review how Starlark unit-test failures report their location. Compare the requested callsite location with a full stack trace and the suggested stacktrace() or print() options. Done means a failing assertion identifies its useful callsite or stack trace.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system, testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100