guidorice / mojo-pytest

Mojo🔥 language test runner plugin for pytest. (aka pytest-mojo)
MIT License
46 stars 1 forks source link

Add filename, line and column number to MojoTestItem #9

Closed guidorice closed 5 months ago

guidorice commented 10 months ago

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 commented 5 months ago

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

franckrasolo commented 5 months ago

Great news, thanks @guidorice!

guidorice commented 4 months ago

@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 commented 4 months ago

@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.