Sure

raw JSON →
2.0.1 verified Mon Apr 27 auth: no python

Sure is an idiomatic assertion library for Python, designed for expressive and readable test assertions. Version 2.0.1 is current. It monkey-patches built-in types like `str`, `list`, `dict` to provide fluent assertion chains (e.g., `"hello".should.equal("hello")`). The library is in maintenance mode with sparse releases.

pip install sure
error ModuleNotFoundError: No module named 'sure'
cause Sure is not installed in the current Python environment.
fix
Run pip install sure to install the package.
error AttributeError: 'str' object has no attribute 'should'
cause Sure has not been imported, so the monkey-patch has not been applied.
fix
Add import sure at the top of your test module.
error AssertionError: <some expression> should equal <value> but got <different value>
cause Sure's assertion mechanism raises this custom error when a predicate fails (e.g., `.should.equal()`).
fix
Check your test logic and the actual value. This is expected behavior; handle with try/except if needed.
gotcha sure monkey-patches built-in types globally. This can affect other libraries or test output when imported.
fix Import sure only in test files or use a test runner that isolates imports. Alternatively, use sure's context manager to limit scope (not available in all versions).
deprecated The pipe syntax (e.g., `|should|`) is deprecated and may be removed in future versions.
fix Use the `.should` attribute syntax instead.
breaking Python 2 support removed in v2.0. The library now requires Python 3.6+.
fix Upgrade to Python 3.6+ if you are on an older version.

Basic usage showing .should chains and the anything sentinel.

import sure

def test_assertions():
    # Fluent assertions via monkey-patched .should
    (2 + 2).should.equal(4)
    "hello".should.contain("ell")
    [1, 2, 3].should.not_.contain(4)

    # Using anything
    from sure import anything
    "abc".should.equal(anything)

    # Assert that a function raises
    import sys
    lambda: 1/0 |should| "raise(ZeroDivisionError)"  # alternative syntax