I'm writing analysis-time tests for my project as per https://docs.bazel.build/versions/master/skylark/testing.html and I'm wondering what the most useful way of reporting failures is.
Using the unittest.bzl
module, I am using asserts.equals
, asserts.true
etc and find the error reporting in the logs somewhat lacking. For example, if an asserts.true
fails the error message is Expected condition to be true, but was false
, with no mention of which line, or what the condition it expected to be true was. In a file full of lots of tests, this isn't very useful! I'm aware one can add a message as an argument to these assertions, but having tailored messages for every assertion doesn't feel ideal either. Is there a way to get at the backtrace caused by the assertion failure at all? Or any other way of accessing the line number/details of assertion failure?
I took the minimal example from your link and added the latest Skylib release to a new WORKSPACE. I then changed the expected value in
_provider_contents_test_impl
to make the test fail.Below is the full output, note the
DEBUG
that contains a lot of useful info (file, line, expectation, actual value).Tracebacks are also supported, see this bug report for example.
tion, actual value).
Tracebacks are also supported, see this bug report for example.
Note that
asserts.equals
will print the actual value on failure, butasserts.true
will not - but you can easily work around this by usingasserts.equals(env, True, test_val, msg)
instead.