Registry / testing / pytest-archon

pytest-archon

JSON →
library0.0.7pypypi✓ verified 86d ago

pytest-archon is a pytest plugin for enforcing architectural boundaries in Python projects. It allows you to define rules that prevent certain imports between modules, ensuring layering and dependency direction. Current version: 0.0.7. Release cadence: infrequent, no set schedule.

pip install pytest-archon
INSTALL
IMPORT
SIG · PYTEST-ARCHON
P
pytest-archon
testingpythonv0.0.7
Install
2.7s avg
Import
86ms
Disk
29MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.7 · 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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.094s · 31MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.7s · import 0.078s · 31MB
29MB installed
● package 29MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

archrule
from pytest_archon import archrule
from pytest_archon.archrule import archrule
The correct import is from the top-level module, not a submodule.
ArchRule
from pytest_archon import archrule
A class ArchRule is not directly importable; use the archrule function.

Define an architecture rule that prevents the 'services' package from importing 'ui' or 'db' packages in the 'myapp' project.

import pytest from pytest_archon import archrule def test_import_rule(): ( archrule("myapp.services") .should_not_import("myapp.ui") .should_not_import("myapp.db") .check("myapp") )
Debug
Known issues
gotchaThe archrule pattern strings are matched as substring matches by default; use precise package names to avoid false positives.
fix
Use exact package/module names, e.g., 'myapp.services' not 'services'.
affects: all
gotchaThe .check() method scans the entire project from the given root, which may be slow on large codebases.
fix
Restrict the scope by passing a subdirectory path or a list of modules to check.
affects: all
gotchaRules are defined as test functions; they are executed with other pytest tests. Ensure your architecture tests are collected and run.
fix
Ensure the test file is in a test directory (e.g., tests/) and follows pytest naming conventions.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pytest_archon'
pytest-archon is not installed or not installed in the current virtual environment.
fix
Run 'pip install pytest-archon' to install the package.
TypeError: archrule() missing 1 required positional argument: 'package'
The archrule function requires the package name as the first argument.
fix
Use archrule('myapp.services') with a string argument.
AttributeError: 'ArchRule' object has no attribute 'should_not_import'
The import is wrong: you imported ArchRule directly, but the correct usage is calling the archrule function.
fix
Use 'from pytest_archon import archrule' and then call archrule() to get the rule builder.
Upgrade
Version history
0.0.7latest on PyPI · released Sep 19, 2025
Audit
Dependencies
pytestrequiredRequired: pytest-archon is a pytest plugin and runs within pytest.
Agent activity
14 hits · last 30 days
node
12
Resources
pytest-archon — pip install pytest-archon · libregistry