Mojo module
testing
Implements various testing utils.
You can import these APIs from the testing
package. For example:
from testing import assert_true
def main():
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)
from testing import assert_true
def main():
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.
Traits
-
Testable
: A trait that a struct should conform to if we do equality testing on it. -
TestableCollectionElement
: A trait for elements that can be tested in a collection.
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_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.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!