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-4.0.1.tar.gz (42.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytestarch-4.0.1-py3-none-any.whl (62.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytestarch-4.0.1.tar.gz
  • Upload date:
  • Size: 42.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pytestarch-4.0.1.tar.gz
Algorithm Hash digest
SHA256 2f288eb8a8a818d3d89a45180d1756c4db2885a7a1281c4ac019665ed97db6b9
MD5 73b5d143e935ffffffd23a214efd885a
BLAKE2b-256 42a288b37e1133457c224155c29ae3619915977063e44fbf0d1780012aeb6a3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytestarch-4.0.1.tar.gz:

Publisher: release.yml on zyskarch/pytestarch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: pytestarch-4.0.1-py3-none-any.whl
  • Upload date:
  • Size: 62.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pytestarch-4.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4dd5adc363b3e1fde72d4b34564f03e62f715cc5e38f1c3a347b0f1cc92168fe
MD5 c8e6a55d072f085917c8f50410167ffd
BLAKE2b-256 ac6e8b6079324672f03fd4b914345ecd2df95a04caf658faf4d7f7e7fa97d543

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytestarch-4.0.1-py3-none-any.whl:

Publisher: release.yml on zyskarch/pytestarch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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