testing
Implements various testing utils.
You can import these APIs from the testing
package. For example:
from testing import assert_true
assert_raises
Context manager that asserts that the block raises an exception.
You can use this to test expected error cases, and to test that the correct errors are raised. For instance:
from testing import assert_raises# Good! Caught the raised error, test passeswith assert_raises(): raise "SomeError"# Also good!with assert_raises(contains="Some"): raise "SomeError"# This will assert, we didn't raisewith assert_raises(): pass# This will let the underlying error propagate, failing the testwith assert_raises(contains="Some"): raise "OtherError"
Fields:
- message_contains (
Optional[String]
): If present, check that the error message contains this literal string.
Implemented traits:
AnyType
Methods:
__init__
__init__(inout self: Self)
Construct a context manager with no message pattern.
__init__(inout self: Self, *, contains: String)
Construct a context manager matching specific errors.
Args:
- contains (
String
): The test will only pass if the error message includes the literal text passed.
__enter__
__enter__(self