pytest-orm-boundaries
💡 Even if you control your imports — boundaries still can leak through the ORM
A pytest-orm-boundaries is a pytest plugin that fails your tests when ORM queries cross your DDD aggregate boundaries.
Currently works with Django ORM.
In domain-driven design, an aggregate is a consistency boundary: code in one
aggregate should not reach into the internals of another. Django's __ relation
lookups make it easy to cross those boundaries silently:
# Purchase and Client belong to different aggregates — this query couples them.
Purchase.objects.get(client__name="John")
pytest-orm-boundaries watches the queries your test suite executes and
reports the ones that step outside their aggregate, whether through __
lookups, subqueries, or other joins.
Install
pip install pytest-orm-boundaries
pytest picks the plugin up automatically.
Configure
Declare your aggregates in boundaries.toml at the project root (or point at
the file with --boundaries-config / the boundaries_config ini option):
[aggregates]
client = ["bookshop.Client"]
book = ["bookshop.Book"]
purchase = ["bookshop.Purchase", "bookshop.PurchaseLine"]
Models are written as app_label.Model. Models not listed in any aggregate are
not checked. Without a config file the plugin emits a warning and runs no checks.
Ignoring files
Add exceptions so that known offenders keep passing while you fix them one file at a time:
[ignore]
files = [
"app/billing.py",
"app/legacy/*",
]
Each entry is a glob (fnmatch,
resolved relative to pytest's root directory and matched against either:
- the file that issues the query, or
- the test file.
If an ignored file runs queries through the whole suite without ever crossing a boundary, the plugin says so at the end:
======================= orm-boundaries: stale ignores ========================
These [ignore] entries no longer suppress any boundary violation - their files are clean now.
Remove them from boundaries.toml:
- app/billing.py
Status
Alpha - testing basic version.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_orm_boundaries-0.2.0.tar.gz.
File metadata
- Download URL: pytest_orm_boundaries-0.2.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bcb3b13f9ff6a914a868a563798481e4797b35715d9a280e3b312ef67d3fdd4
|
|
| MD5 |
c896becf61bdd6c89a46df38fbd77331
|
|
| BLAKE2b-256 |
66cafe3d460f232e248255a4e11c05f3958fc13910f37aae70ba6353db63c8d3
|
File details
Details for the file pytest_orm_boundaries-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pytest_orm_boundaries-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a79273ca72304760e5583c3bb0630571a451385d7bebf297b3efac6f76036462
|
|
| MD5 |
aba51ae6f5c0c78a0c64ad0b680b0f1c
|
|
| BLAKE2b-256 |
7ccf7c3b9c55bda860acf8840d3d43c08e4dd7261141d557982527160c66841e
|