Rule your architecture like a real developer
Low maintenance activity. Last release 14 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and recent releases.
Consider insteadPyTestArchPythie’s Index: 70261.2K downloads/moCompare →
pip install pytest-archonpytest-archon
pytest-archon is a little tool that helps you structure (large) Python projects. This
tool allows you to define architectural boundaries in your code, also known as
forbidden dependencies.
Explicitly defined architectural boundaries helps you keep your code in shape. It avoids the creation of circular dependencies. New people on the project are made aware of the structure through a simple set of rules, instead of lore.
Installation
The simple way:
pip install pytest-archon
Usage
pytest-archon can be used to define architectural boundaries from (unit) tests. Because they're tests, they can be closely tied to the actual application.
You can use pytest-archon in tests by simply importing the archrule function. Using
this function you can construct import tests:
from pytest_archon import archrule
def test_rule_basic():
(
archrule("name", comment="some comment")
.match("pytest_archon.col*")
.exclude("pytest_archon.colgate")
.should_not_import("pytest_archon.import_finder")
.should_import("pytest_archon.core*")
.check("pytest_archon")
)
- To match the modules and constraints,
fnmatch syntax is used (the
default). You can also use
regular expressions
by supplying the
use_regex=Trueargument toarchrule(). Example:archrule(..., use_regex=True).match(...). .exclude()is optional.should_import()and.should_not_import()can be combined and can occur multiple times..may_import()can be used in combination with.should_not_import()..check()needs either a module object or a string
The check() method can have a few optional parameters, that alter the way the checks
are performed.
- Without parameters, the whole file is checked for imports. So imports done in functions and methods are also found. Transitive dependencies are also checked