re-assert
raw JSON → 1.1.0 verified Mon Apr 27 auth: no python
A library to show where your regex match assertion failed. It provides a helper to clarify regex failures in tests. Current version: 1.1.0, release cadence: low, maintained by asottile.
pip install re-assert Common errors
error ImportError: cannot import name 're_assert' ↓
cause Incorrect import: the module is named re_assert (with underscore), not re-assert (with hyphen).
fix
Use 'from re_assert import ReAssert' (note underscore)
error AttributeError: module 're_assert' has no attribute 'ReAssert' ↓
cause Version mismatch or incorrect installation. Ensure package is installed as 're-assert'.
fix
Run 'pip install re-assert' and import with 'from re_assert import ReAssert'
error TypeError: 'ReAssert' object is not callable ↓
cause Attempting to call ReAssert as a function. It is a class, instantiate it first.
fix
matcher = ReAssert(pattern); then matcher == 'string'
Warnings
gotcha ReAssert uses __eq__ to perform matching. Ensure you are comparing the ReAssert object to a string, not the other way around. ↓
fix Use 'matcher == string' pattern.
gotcha The library is designed for testing; it does not raise exceptions but returns False and prints diagnostic info. Do not use it for production regex validation without assertions. ↓
fix Use in test suites with pytest or unittest.
Imports
- ReAssert
from re_assert import ReAssert
Quickstart
from re_assert import ReAssert
# Pattern with group names
pattern = r"(?P<name>\w+) (?P<age>\d+)"
matcher = ReAssert(pattern)
# This assertion will fail with a detailed message
# matcher == 'John 30 extra'
# Uncomment to see error: matcher == 'John 30' (this matches)