IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0.0b1
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

testing

Implements various testing utils.

You can import these APIs from the testing package. For example:

from std.testing import assert_true

def main() raises:
x = 1
y = 2
try:
assert_true(x==1)
assert_true(y==2)
assert_true((x+y)==3)
print("All assertions succeeded")
except e:
print("At least one assertion failed:")
print(e)

Structs

  • assert_raises: Context manager that asserts that the block raises an exception.

Functions

  • assert_almost_equal: Asserts that the input values are equal up to a tolerance. If it is not then an Error is raised.
  • assert_equal: Asserts that the input values are equal. If it is not then an Error is raised.
  • assert_equal_pyobj: Asserts that the PythonObjects are equal. If it is not then an Error is raised.
  • assert_false: Asserts that the input value is False and raises an Error if it's not.
  • assert_is: Asserts that the input values have the same identity. If they do not then an Error is raised.
  • assert_is_not: Asserts that the input values have different identities. If they do not then an Error is raised.
  • assert_not_equal: Asserts that the input values are not equal. If it is not then an Error is raised.
  • assert_true: Asserts that the input value is True and raises an Error if it's not.