{"id":8980,"library":"expects","title":"Expects: Expressive TDD/BDD Assertion Library","description":"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.","status":"maintenance","version":"0.9.0","language":"en","source_language":"en","source_url":"https://github.com/jaimegildesagredo/expects","tags":["TDD","BDD","assertions","testing","unit-testing"],"install":[{"cmd":"pip install expects","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary usage pattern is to import 'expect' and specific matchers, or use 'from expects import *' for convenience, as 'expects.expect' is not the intended API.","wrong":"import expects\nexpects.expect([])","symbol":"expect","correct":"from expects import expect, be_empty, equal"},{"note":"Commonly used for quick setup to bring 'expect' and all built-in matchers into the global namespace.","symbol":"* (all matchers)","correct":"from expects import *"}],"quickstart":{"code":"from expects import *\n\ndef divide(a, b):\n    if b == 0:\n        raise ValueError(\"Cannot divide by zero\")\n    return a / b\n\n# Example assertions\nexpect(5).to(equal(5))\nexpect([]).to(be_empty)\nexpect(False).not_to(be_true)\nexpect(lambda: divide(1, 0)).to(raise_error(ValueError, 'Cannot divide by zero'))\nexpect({'name': 'Alice'}).to(have_key('name'))\n\nprint(\"All assertions passed!\")","lang":"python","description":"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."},"warnings":[{"fix":"For larger projects, consider importing `expect` and specific matchers explicitly: `from expects import expect, equal, be_empty`.","message":"The primary recommended import, `from expects import *`, pollutes the global namespace with `expect` and all matcher functions (e.g., `equal`, `be_empty`). While convenient for small tests, this can lead to name collisions in larger codebases.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review the GitHub repository for any unreleased changes or forks. For critical projects, consider alternative, more actively maintained assertion libraries if future Python compatibility is a concern.","message":"The `expects` library has not seen a new release since October 2018 (version 0.9.0). While functional, it might not be actively maintained, which could lead to compatibility issues with newer Python versions, lack of bug fixes for modern environments, or unaddressed security vulnerabilities.","severity":"gotcha","affected_versions":"0.9.0 and earlier"},{"fix":"Ensure you are using a Python 3.x environment (3.4+ is recommended by the library itself) for the most stable experience. If sticking with Python 2.7, explicitly pin `expects<0.9.0` or test thoroughly.","message":"Despite its 2018 release date, version 0.9.0 of `expects` explicitly states compatibility with Python 2.7. However, mixing Python 2 and 3 environments with libraries released around the 2.x to 3.x transition (e.9., some `0.9.0` releases like `cmd2` v0.9.0) has historically led to `pip` installing incorrect versions. Verify your Python interpreter version and `expects` installation if encountering unexpected behavior, especially in older Python 2.7 environments.","severity":"gotcha","affected_versions":"0.9.0, primarily in Python 2.7 environments"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Add `from expects import *` or `from expects import expect` at the top of your test file.","cause":"The `expect` callable was not imported into the current scope.","error":"NameError: name 'expect' is not defined"},{"fix":"Ensure consistent indentation (typically 4 spaces) throughout your Python code, especially after colons for code blocks (e.g., function definitions, `if` statements).","cause":"This usually occurs when copy-pasting code, and Python's strict indentation rules are violated.","error":"IndentationError: expected an indented block"},{"fix":"Remove the parentheses when using matchers with `.to()`, unless the matcher explicitly expects arguments (e.g., `equal(5)`). Correct: `expect(value).to(be_empty)`.","cause":"Attempting to call a matcher directly (e.g., `expect(value).to(be_empty())` instead of `expect(value).to(be_empty)`). Matchers are properties, not functions, when used with `.to()`.","error":"TypeError: 'Matcher' object is not callable"}]}