Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom error message in assertion module #121

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

LINKIWI
Copy link

@LINKIWI LINKIWI commented Jun 27, 2024

This PR proposes the addition of an optional secondary argument to ctx.assert(...) which enables unit test callsites to specify a custom assertion failure error message.

This looks like, for example:

def test_foo(ctx):
    ctx.assert(False)

def test_foo_message(ctx):
    ctx.assert(False, "foo error message")

Executing these tests results in:

[foo.sky:2:15] assertion failed
...
[foo.sky:4:15] assertion failed: foo error message
...

I added corresponding unit test coverage.

$ bazelisk test --cache_test_results=no //go/...
INFO: Invocation ID: bc5157d2-13f6-4d45-84b3-42aae65fc926
INFO: Analyzed 10 targets (0 packages loaded, 137 targets configured).
INFO: Found 5 targets and 5 test targets...
INFO: Elapsed time: 2.453s, Critical Path: 0.51s
INFO: 6 processes: 1 internal, 5 processwrapper-sandbox.
INFO: Build completed successfully, 6 total actions
//go/assertmodule:assertmodule_test                                      PASSED in 0.3s
//go/hashmodule:hashmodule_test                                          PASSED in 0.4s
//go/protomodule:protomodule_test                                        PASSED in 0.5s
//go/urlmodule:urlmodule_test                                            PASSED in 0.4s
//go/yamlmodule:yamlmodule_test                                          PASSED in 0.3s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant