{"id":24416,"library":"pytest-archon","title":"pytest-archon","description":"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.","status":"active","version":"0.0.7","language":"python","source_language":"en","source_url":"https://github.com/jabes/bibliopixel","tags":["pytest","architecture","testing","imports","linting"],"install":[{"cmd":"pip install pytest-archon","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required: pytest-archon is a pytest plugin and runs within pytest.","package":"pytest","optional":false}],"imports":[{"note":"The correct import is from the top-level module, not a submodule.","wrong":"from pytest_archon.archrule import archrule","symbol":"archrule","correct":"from pytest_archon import archrule"},{"note":"A class ArchRule is not directly importable; use the archrule function.","wrong":"","symbol":"ArchRule","correct":"from pytest_archon import archrule"}],"quickstart":{"code":"import pytest\nfrom pytest_archon import archrule\n\ndef test_import_rule():\n    (\n        archrule(\"myapp.services\")\n        .should_not_import(\"myapp.ui\")\n        .should_not_import(\"myapp.db\")\n        .check(\"myapp\")\n    )","lang":"python","description":"Define an architecture rule that prevents the 'services' package from importing 'ui' or 'db' packages in the 'myapp' project."},"warnings":[{"fix":"Use exact package/module names, e.g., 'myapp.services' not 'services'.","message":"The archrule pattern strings are matched as substring matches by default; use precise package names to avoid false positives.","severity":"gotcha","affected_versions":"all"},{"fix":"Restrict the scope by passing a subdirectory path or a list of modules to check.","message":"The .check() method scans the entire project from the given root, which may be slow on large codebases.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure the test file is in a test directory (e.g., tests/) and follows pytest naming conventions.","message":"Rules are defined as test functions; they are executed with other pytest tests. Ensure your architecture tests are collected and run.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'pip install pytest-archon' to install the package.","cause":"pytest-archon is not installed or not installed in the current virtual environment.","error":"ModuleNotFoundError: No module named 'pytest_archon'"},{"fix":"Use archrule('myapp.services') with a string argument.","cause":"The archrule function requires the package name as the first argument.","error":"TypeError: archrule() missing 1 required positional argument: 'package'"},{"fix":"Use 'from pytest_archon import archrule' and then call archrule() to get the rule builder.","cause":"The import is wrong: you imported ArchRule directly, but the correct usage is calling the archrule function.","error":"AttributeError: 'ArchRule' object has no attribute 'should_not_import'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}