modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo
Other
21.79k stars 2.53k forks source link

[Feature Request] assert_raises should report calling location #2692

Closed keith closed 1 week ago

keith commented 2 weeks ago

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 https://github.com/modularml/mojo/blob/f5f5109541c31615a68a3c4b58bd1e75b59625f6/stdlib/src/testing/testing.mojo#L386

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:

https://github.com/modularml/mojo/blob/f5f5109541c31615a68a3c4b58bd1e75b59625f6/stdlib/test/collections/test_list.mojo#L404-L414

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