Install & Compatibility
Where this runs
tested against v0.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.022s · 17.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.018s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ANY_DATETIME_STR
✓ from anys import ANY_DATETIME_STR
ANY_INT
✓ from anys import ANY_INT
ANY_STR
✓ from anys import ANY_STR
AnyGT
✓ from anys import AnyGT
AnyLT
✓ from anys import AnyLT
AnyMatch
✓ from anys import AnyMatch
✗ import anys; assert foo == anys.AnyMatch(...)
While technically possible, the documentation examples primarily use direct `from anys import ...` for brevity and clarity when using specific matchers.
This quickstart demonstrates how to use `anys` for flexible assertions, particularly with dynamic data like API responses. It uses `ANY_STR` to match any string and `ANY_DATETIME_STR` to match any valid ISO 8601 datetime string, allowing the test to pass even if the exact values for `id`, `created_at`, `status`, or `last_login` are not known in advance.
from anys import ANY_DATETIME_STR
def test_api_response():
# Imagine this is a dynamic response from an API or function
dynamic_data = {
"id": "user-123",
"name": "Test User",
"created_at": "2024-04-12T10:30:00Z",
"details": {
"status": "active",
"last_login": "2024-04-12T10:29:55Z"
}
}
# Assert against a structure with matchers for dynamic fields
expected_pattern = {
"id": ANY_STR, # Match any string
"name": "Test User",
"created_at": ANY_DATETIME_STR, # Match any valid ISO datetime string
"details": {
"status": ANY_STR,
"last_login": ANY_DATETIME_STR
}
}
assert dynamic_data == expected_pattern
print("Assertion successful: Dynamic data matches expected pattern!")
test_api_response()
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'anys'
The 'anys' library is not installed in the Python environment.
fixInstall the 'anys' library using pip: 'pip install anys'.
ImportError: cannot import name 'ANY_DATETIME_STR' from 'anys'
The 'ANY_DATETIME_STR' matcher is not available in the 'anys' library.
fixUse the 'ANY_STR' matcher from 'anys' for string comparisons.
TypeError: 'ANY' object is not callable
Attempting to call an 'ANY' matcher as a function, which is not supported.
fixUse 'ANY' as a value in assertions without calling it as a function.
AssertionError: assert <value> == <anys matcher>
An 'anys' matcher encountered a TypeError or ValueError during comparison (e.g., trying to match a regex against an integer), but the library silently suppressed the error and evaluated the comparison to `False` instead of raising a descriptive exception. This leads to a generic `AssertionError` without clearly indicating the underlying type mismatch.
fixExplicitly check the expected type of the value using `isinstance()` before applying the `anys` matcher, or use `anys` matchers specifically designed for the expected numeric or string types (e.g., `ANY_INT`, `AnyGT`, `ANY_STR`).
NameError: name 'ANY_DATETIME_STR' is not defined
The `ANY_DATETIME_STR` (or other top-level `anys` matchers like `ANY_INT`, `ANY_STR`) constant was used without being explicitly imported from the `anys` library. This is a common Python `NameError` when a constant or object is referenced before it has been assigned or imported.
fixAdd the necessary import statement: `from anys import ANY_DATETIME_STR` (or the specific matcher you intend to use) at the beginning of your Python file.
Upgrade
Version history
0.3.1latest on PyPI · released Dec 1, 2024
Audit
Dependencies
pythonrequiredRequires Python 3.8 or higher for compatibility.