django-consistency-enforcer
raw JSON → 0.5.1 verified Sat May 09 auth: no python
A Django library that provides testing utilities to enforce internal consistency across Django concepts (models, signals, permissions, etc.). Current version is 0.5.1, with monthly releases.
pip install django-consistency-enforcer Common errors
error ImportError: cannot import name 'ConsistencyEnforcer' from 'consistency_enforcer' ↓
cause The library version is older than 0.5.0, where the class was in a submodule.
fix
Either upgrade the library (
pip install --upgrade django-consistency-enforcer) or use the old import: from consistency_enforcer.enforcer import ConsistencyEnforcer. error AttributeError: module 'consistency_enforcer' has no attribute 'enforce_consistency' ↓
cause Trying to import a deprecated function that was removed in 0.5.0.
fix
Use the
ConsistencyEnforcer class instead: from consistency_enforcer import ConsistencyEnforcer. Warnings
breaking In version 0.5.0, the import path for `ConsistencyEnforcer` changed from `consistency_enforcer.enforcer` to `consistency_enforcer`. Old imports will break. ↓
fix Update imports to `from consistency_enforcer import ConsistencyEnforcer`.
deprecated The `enforce_consistency` decorator is deprecated in favor of using the `ConsistencyEnforcer` class directly. It will be removed in version 0.6. ↓
fix Replace `@enforce_consistency` with a call to `enforcer.check_all()` inside the test.
gotcha The enforcer may be slow on large projects because it inspects all Django apps' models and signals. Run it only on specific apps or models in CI to avoid timeout. ↓
fix Pass app labels to `check_all(app_labels=['myapp'])` to limit scope.
Imports
- ConsistencyEnforcer wrong
from consistency_enforcer.enforcer import ConsistencyEnforcercorrectfrom consistency_enforcer import ConsistencyEnforcer - enforce_consistency wrong
from consistency_enforcer.decorators import enforce_consistencycorrectfrom consistency_enforcer import enforce_consistency
Quickstart
# In your test file
from django.test import TestCase
from consistency_enforcer import ConsistencyEnforcer
class MyModelTest(TestCase):
def test_model_consistency(self):
enforcer = ConsistencyEnforcer()
# This will check that all model references are consistent
enforcer.check_all()