Skip to content

Support custom error message in assertion module #121

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

Merged
merged 2 commits into from
Apr 7, 2025

Conversation

LINKIWI
Copy link
Contributor

@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

@sushain-stripe sushain-stripe merged commit 6d28b76 into stripe:trunk Apr 7, 2025
4 checks passed
@LINKIWI
Copy link
Contributor Author

LINKIWI commented Apr 7, 2025

Hi @sushain-stripe, apologies for the churn, I realized that we had actually enhanced this patch internally but I forgot to file a PR for it. Sent another PR #130 for this.

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.

2 participants