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

Add filename, line and column number to MojoTestItem #9

Closed
guidorice opened this issue Nov 23, 2023 · 4 comments · Fixed by #15
Closed

Add filename, line and column number to MojoTestItem #9

guidorice opened this issue Nov 23, 2023 · 4 comments · Fixed by #15
Assignees
Labels
enhancement New feature or request

Comments

@guidorice
Copy link
Owner

guidorice commented Nov 23, 2023

When a python test is collected by pytest, it reports a line number and context like this:

    def test_ex():
>       raise Exception("here")
E       Exception: here

path/to/test_file.py:2: Exception

In IDEs like VSCode, we can quickly navigate to the failed test function/class by Cmd-click on the file:line.

In mojo-pytest this would be a useful enhancement at least to have at least the line number. It should be possible to resolve at the line number of failed MojoTestItems by scanning for the test name, and/or the assert failure message, in the mojo source file.

@guidorice guidorice added the enhancement New feature or request label Nov 23, 2023
@guidorice guidorice changed the title Add line number and context to MojoTestItem Add line number to MojoTestItem Nov 23, 2023
@guidorice
Copy link
Owner Author

guidorice commented May 2, 2024

In mojo v24.3 there are some very useful sounding enhancements

debug_assert() now prints its location (filename, line, and column where it was called) in its error message. Similarly, the assert helpers in the testing module now include location information in their messages. changelog

@guidorice guidorice self-assigned this May 2, 2024
@guidorice guidorice changed the title Add line number to MojoTestItem Add filename, line and column number to MojoTestItem May 2, 2024
@franckrasolo
Copy link

Great news, thanks @guidorice!

franckrasolo added a commit to franckrasolo/mojo-playground.nix that referenced this issue May 7, 2024
@guidorice
Copy link
Owner Author

guidorice commented May 7, 2024

@franckrasolo If you give it a try, just a tip you will need to manually copy over the latest MojoTest struct from https://github.com/guidorice/mojo-pytest/blob/58512e8ed1a76fa67f49d228d1758dec8be525f2/example/tests/util.mojo
Thanks for your interest!

@franckrasolo
Copy link

franckrasolo commented May 7, 2024

@guidorice Yes, I did exactly that as I'm currently using everything that's in the examples folder (untracked by Git) and realised that it was a little out of date.

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

Successfully merging a pull request may close this issue.

2 participants