Mojo test
Did anyone get unit tests working?
I run
mojo test
on the following folder structure:
But it doesn't pick up my tests Total Discovered Tests: 0
.
The test_tensor.🔥 contains a function:
As described in the docs: https://docs.modular.com/mojo/tools/testing
Any suggestions?Testing | Modular Docs
Testing Mojo programs.
3 Replies
Same issue. Not sure what I'm doing wrong.
So I've taken to including a
main()
in each test file and adding each test function there:
Then, I can do a shell command to run them all:
find ./ -type f -name "test_*.mojo" -execdir mojo "{}" \;
Output:
Not pretty, but is a workaround until I figure out what I'm doing wrong that prevents mojo test
from picking up my test files & functions. 😊
oh wow. I was just goofing around a bit and removed the __init__.mojo
file; now mojo test
works. Although I need to rework my test code, as removing the init file messed with my imports. Hmmm....
mojo test -I .
worked for me. Still need to tidy test cases a bit, but at least this is a bit of a win.
I forgot to include a pic of the output from mojo test -I .
-- keep in mind that the -I .
tells it that it should add the current directory (.
) to Mojo's import path for the purpose of the test run.Solved! Thanks @bunny , removing the
__init__.mojo
helped fixed the problem.