Skip to main content

Test framework for software architecture based on imports between modules

Project description

Welcome to PyTestArch

PyTestArch is an open source library that allows users to define architectural rules and test their code against them. It is generally inspired by ArchUnit.

Installation Guide

PyTestArch is available via PyPI and can be installed e.g. via pip: pip install pytestarch. To also install the optional dependency matplotlib, which is required to draw the created dependency graphs, install pytestarch[visualization]

Usage Guide

Three steps are required to test an architectural rule:

  1. Create an evaluable representation of the source code you want to test
from pytestarch import get_evaluable_architecture

evaluable = get_evaluable_architecture("/home/dummy/project", "/home/dummy/project/src")

This will scan all python files under /home/dummy/project/src for imports and build an internal representation that can later be queried. The first parameter /home/dummy/project helps PyTestArch to differentiate between internal and external dependencies. This evaluable can be used for multiple architectural rule checks; if you are using pytest, you could use a fixture for this evaluable object.

  1. Define an architectural rule
from pytestarch import Rule

rule = (
    Rule() 
    .modules_that() 
    .are_named("project.src.moduleB") 
    .should_not() 
    .be_imported_by_modules_that() 
    .are_sub_modules_of("project.src.moduleA") 
)

This rule represents the architectural requirements that a module named "project.src.moduleB" should not be imported by any module that is a submodule of "project.src.moduleA", excluding "project.src.moduleA" itself.

  1. Evaluate your code against this rule
rule.assert_applies(evaluable)

That's it!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytestarch-3.1.1.tar.gz (44.4 kB view details)

Uploaded Source

Built Distribution

pytestarch-3.1.1-py3-none-any.whl (61.9 kB view details)

Uploaded Python 3

File details

Details for the file pytestarch-3.1.1.tar.gz.

File metadata

  • Download URL: pytestarch-3.1.1.tar.gz
  • Upload date:
  • Size: 44.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pytestarch-3.1.1.tar.gz
Algorithm Hash digest
SHA256 aca758b59d180a198cf50104a861a6b54e3302fd12f6e5dcd3e211ddb08147a4
MD5 abd254c77ead5fae51966f263562c21c
BLAKE2b-256 e32c676e6bd6db4a73d0b7bfedf157fc9dddc3f49f41c7adef7eb94d5999f2c4

See more details on using hashes here.

File details

Details for the file pytestarch-3.1.1-py3-none-any.whl.

File metadata

  • Download URL: pytestarch-3.1.1-py3-none-any.whl
  • Upload date:
  • Size: 61.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pytestarch-3.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bdd14001a178faa5f01908b35891582f3c6deba30b2ae4898cdfb128a2be31f6
MD5 187084d9a9bf0b6203fde0e587deb6cf
BLAKE2b-256 777ee4d0ce0349b0ff23d1de190763699dc0ca7e250cb6a0650f8391ae7b0fe8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page