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

[Feature Request] assert_raises should report calling location #2692

Closed
1 task done
keith opened this issue May 16, 2024 · 0 comments
Closed
1 task done

[Feature Request] assert_raises should report calling location #2692

keith opened this issue May 16, 2024 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library

Comments

@keith
Copy link

keith commented May 16, 2024

Review Mojo's priorities

What is your request?

It would be useful if the error message produced when assert_raises fails, and therefore it raises itself

raise Error("AssertionError: Didn't raise")

included the location of the caller who didn't raise.

What is your motivation for this change?

Currently if you have a single test file with multiple assert_raises conditions, like this file:

with assert_raises(contains="ValueError: Given element is not in list"):
__type_of(test_list_a).index(test_list_a, 50, start=-5, end=-1)
with assert_raises(contains="ValueError: Given element is not in list"):
__type_of(test_list_a).index(test_list_a, 50, start=0, end=-1)
with assert_raises(contains="ValueError: Given element is not in list"):
__type_of(test_list_a).index(test_list_a, 10, start=-4, end=-1)
with assert_raises(
contains=(
"Given 'start' parameter (5) is out of range. List only has 5"
" elements."
)

If one of the conditions fails, the error message is just:

Unhandled exception caught during execution: AssertionError: Didn't raise

with no indication of where the assertion is coming from

Any other details?

No response

@keith keith added enhancement New feature or request mojo-repo Tag all issues with this label labels May 16, 2024
@JoeLoser JoeLoser added good first issue Good for newcomers mojo-stdlib Tag for issues related to standard library labels May 17, 2024
rd4com added a commit to rd4com/mojo_branch that referenced this issue May 17, 2024
Signed-off-by: rd4com <144297616+rd4com@users.noreply.github.com>
rd4com added a commit to rd4com/mojo_branch that referenced this issue May 17, 2024
Signed-off-by: rd4com <144297616+rd4com@users.noreply.github.com>
@keith keith closed this as completed May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library
Projects
None yet
Development

No branches or pull requests

2 participants