Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

test.error

import test.error

test lifts part of this module out to its own top level; each name below is shown with the path that reaches it. Anything still spelled test.error.* needs import 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

FieldTypeDescription
matcherThe matcher that failed, e.g. 'to_be', 'to_contain'.
expectedWhat the matcher was told to expect.
receivedWhat it was actually given.
has_valuesWhether expected and received are worth showing.
detailsPre-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 of matcher, 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)