test.error
import test.error
testlifts part of this module out to its own top level; each name below is shown with the path that reaches it. Anything still spelledtest.error.*needsimport test.error.
The errors the test module raises, kept in a module of their own so that the assertion side and the runner side can both name them without importing each other.
Only AssertionError normally reaches a test author, and only by being
caught for them. Everything else in here marks a mistake in how the
framework itself was used, and is meant to stop the run.
Classes
AssertionError
class test.AssertionError < Error
A matcher that did not hold.
The runner catches these, so a test body never has to. What separates one from any other error raised inside a test is that the framework knows how to display it: it carries the two values that disagreed, and whatever extra lines (a diff, a hint) the matcher wanted shown underneath.
import test { AssertionError }
catch {
expect(1).to_be(2)
} as error {
echo error.matcher
echo error.expected
echo error.received
}
to_be
2
1
Fields
| Field | Type | Description |
|---|---|---|
matcher | The matcher that failed, e.g. 'to_be', 'to_contain'. | |
expected | What the matcher was told to expect. | |
received | What it was actually given. | |
has_values | Whether expected and received are worth showing. | |
details | Pre-rendered lines to print underneath the message: a structural diff, the calls a mock actually received, a… |
Constructor
test.AssertionError(message, info)
Parameters
message(string) — the one-line summary.info(?dict) — any ofmatcher,expected,received,has_values,details.
TestSetupError
class test.TestSetupError < Error
The framework was asked to do something that does not make sense: a matcher given the wrong kind of argument, a hook registered outside any suite, a reporter name that does not exist.
This is never a test failing. It stops the run, because carrying on would report results that do not mean what they say.
Constructor
test.TestSetupError(message)