bazelbuild / bazel-skylib

Common useful functions and rules for Bazel
https://bazel.build/
Apache License 2.0
383 stars 179 forks source link

Show line number of the failing assert in unittests #290

Open hlopko opened 3 years ago

hlopko commented 3 years ago

Hi dear Skylib maintainers,

right now we 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.

Thank you!

tetromino commented 3 years ago

This not an issue in skylib but a lack of a feature in starlark.

As far as I know, starlark prints the stack trace only on a fatal error - and that halts further evaluation.

To allow stack traces in failing unit tests without halting evaluation, starlark would need to add something like a stacktrace() builtin or perhaps a with_stacktrace optional named parameter to print().

hlopko commented 3 years ago

Oh good point, I was thinking about people at the Bazel team who would be able to fix it, not about where to file it properly. I'll re-file at bazelbuild/bazel. Thank you!