Expects: Expressive TDD/BDD Assertion Library

0.9.0 · maintenance · verified Thu Apr 16

Expects is an expressive and extensible TDD/BDD assertion library for Python, designed to make test assertions clear and readable in a TDD/BDD style. It supports a wide range of built-in matchers and allows for defining custom ones. The current stable version is 0.9.0, released in October 2018. Given the age of the last release, the library is in a maintenance state rather than active development.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic usage of `expect` and several built-in matchers like `equal`, `be_empty`, `not_to`, `raise_error`, and `have_key`. It showcases how to write expressive assertions for common testing scenarios.

from expects import *

def divide(a, b):
    if b == 0:
        raise ValueError("Cannot divide by zero")
    return a / b

# Example assertions
expect(5).to(equal(5))
expect([]).to(be_empty)
expect(False).not_to(be_true)
expect(lambda: divide(1, 0)).to(raise_error(ValueError, 'Cannot divide by zero'))
expect({'name': 'Alice'}).to(have_key('name'))

print("All assertions passed!")

view raw JSON →