Python assert
Hi all, I am trying to use some existing Python code in Mojo. I couldn't find an alternative for the "assert" statements I use for testing the code. What's the best solution for this?
6 Replies
I tried this, but I think it only works in debug mode.
debug_assert(2==3, "error")
is ignored when I run the code in standard modein that case you could implement your on assert_equal function and return https://docs.modular.com/mojo/stdlib/builtin/error.html
Modular Docs - error
Module
otherwise, I would look if I can interop with https://docs.python.org/3/library/unittest.html?highlight=unittest#module-unittest
Python documentation
unittest — Unit testing framework
Source code: Lib/unittest/init.py(If you are already familiar with the basic concepts of testing, you might want to skip to the list of assert methods.) The unittest unit testing framework was ...
^this last lib exports a TestCase object which has methods like assertEqual, assertTrue... etc
ok, I'll try this. Thanks!