{"id":4885,"library":"assertpy","title":"AssertPy","description":"AssertPy is a simple assertion library for Python unit testing with a fluent API, inspired by AssertJ for Java. It allows for highly readable and chainable assertions. The current version is 1.1, and it has an active release cadence with frequent updates.","status":"active","version":"1.1","language":"en","source_language":"en","source_url":"https://github.com/assertpy/assertpy","tags":["testing","assertions","unit-testing","fluent-api","test-framework"],"install":[{"cmd":"pip install assertpy","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"The primary entry point for all fluent assertions.","symbol":"assert_that","correct":"from assertpy import assert_that"},{"note":"Used as a context manager to collect multiple assertion failures without halting execution immediately.","symbol":"soft_assertions","correct":"from assertpy import soft_assertions"},{"note":"Renamed from `assert_soft` in v0.10; logs warnings instead of raising an AssertionError.","wrong":"from assertpy import assert_soft","symbol":"assert_warn","correct":"from assertpy import assert_warn"}],"quickstart":{"code":"from assertpy import assert_that, soft_assertions\n\ndef test_basic_assertions():\n    assert_that(1 + 2).is_equal_to(3)\n    assert_that('foobar').is_length(6).starts_with('foo').ends_with('bar')\n    assert_that(['a', 'b', 'c']).contains('a').does_not_contain('x')\n    print('Basic assertions passed.')\n\ndef test_soft_assertions():\n    with soft_assertions():\n        assert_that(1).is_equal_to(2)  # This will fail\n        assert_that('hello').is_length(10) # This will also fail\n    print('Soft assertions completed. Failures (if any) are collected.')\n\ntest_basic_assertions()\ntest_soft_assertions()","lang":"python","description":"This quickstart demonstrates basic chained assertions using `assert_that` and shows how to use `soft_assertions` as a context manager to collect multiple failures before raising a single `AssertionError` at the end of the block."},"warnings":[{"fix":"Update calls from `assert_soft()` to `assert_warn()`.","message":"The `assert_soft()` function was renamed to `assert_warn()`.","severity":"breaking","affected_versions":"v0.10 and later"},{"fix":"Change all uses of `extract()` to `extracting()`.","message":"The `extract()` helper function was renamed to `extracting()`.","severity":"breaking","affected_versions":"v0.9 and later"},{"fix":"Ensure you are using a Python 3 environment (Python 3.4-3.8 for v1.1) for full compatibility. Check `assertpy`'s PyPI classifiers for specific version support.","message":"Older versions of AssertPy supported Python 2.x, but modern versions are Python 3.x only. Specific older Python 3 versions (e.g., 3.3, 2.6) have also been dropped over time.","severity":"gotcha","affected_versions":"<=v0.13 (Python 2.6 dropped), <=v0.9 (Python 3.3 dropped)"},{"fix":"Use raw strings (`r'pattern'`) for regex patterns and include `^` and `$` anchors for full string matching if desired.","message":"When using `matches()` for regular expression assertions, be aware that it performs a partial match (like `re.match`). For exact full string matches, include anchors (e.g., `^...$`) in your regex pattern.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Utilize the `include` (or `ignore`) keyword argument in `is_equal_to(expected_dict, include=['key1', 'key2'])` for precise dict comparisons.","message":"For `dict` equality comparisons with `is_equal_to()`, you can control which keys are included or ignored. If not specified, all keys are compared.","severity":"gotcha","affected_versions":"v0.14 and later (for `include` flag)"},{"fix":"Ensure Python 3 is used for snapshot tests and add the `__snapshots` directory (or custom path) to your version control.","message":"Snapshot testing (`.snapshot()`) requires Python 3.x and saves artifacts to disk (e.g., `__snapshots` directory by default). These artifacts should be committed to version control.","severity":"gotcha","affected_versions":"v0.13 and later"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}