PyTestArch


NamePyTestArch JSON
Version 4.0.1 PyPI version JSON
download
home_pageNone
SummaryTest framework for software architecture based on imports between modules
upload_time2025-08-08 12:54:43
maintainerzyskarch
docs_urlNone
authorzyskarch
requires_python>=3.9
licenseApache-2.0
keywords architecture test
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://www.archunit.org/).

## Installation Guide
PyTestArch is available via [PyPI](https://pypi.org/project/pytestarch/) 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](https://docs.pytest.org/en/7.1.x/),
you could use a fixture for this evaluable object.

2) 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.

3) Evaluate your code against this rule

```
rule.assert_applies(evaluable)
```
That's it!


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "PyTestArch",
    "maintainer": "zyskarch",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "zyskarch@gmail.com",
    "keywords": "architecture, test",
    "author": "zyskarch",
    "author_email": "zyskarch@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/42/a2/88b37e1133457c224155c29ae3619915977063e44fbf0d1780012aeb6a3e/pytestarch-4.0.1.tar.gz",
    "platform": null,
    "description": "# Welcome to PyTestArch\n\nPyTestArch is an open source library that allows users to define architectural rules and test their code against them. It is \ngenerally inspired by [ArchUnit](https://www.archunit.org/).\n\n## Installation Guide\nPyTestArch is available via [PyPI](https://pypi.org/project/pytestarch/) and can be installed e.g. via pip: `pip install pytestarch`. To also install the\noptional dependency matplotlib, which is required to draw the created dependency graphs, install `pytestarch[visualization]`\n\n## Usage Guide\nThree steps are required to test an architectural rule:\n\n1) Create an evaluable representation of the source code you want to test\n\n```\nfrom pytestarch import get_evaluable_architecture\n\nevaluable = get_evaluable_architecture(\"/home/dummy/project\", \"/home/dummy/project/src\")\n```\nThis will scan all python files under /home/dummy/project/src for imports and build an internal representation that can\nlater be queried. The first parameter /home/dummy/project helps PyTestArch to differentiate between internal and external \ndependencies. This evaluable can be used for multiple architectural rule checks; if you are using [pytest](https://docs.pytest.org/en/7.1.x/),\nyou could use a fixture for this evaluable object.\n\n2) Define an architectural rule\n```\nfrom pytestarch import Rule\n\nrule = (\n    Rule() \n    .modules_that() \n    .are_named(\"project.src.moduleB\") \n    .should_not() \n    .be_imported_by_modules_that() \n    .are_sub_modules_of(\"project.src.moduleA\") \n)\n```\n\nThis rule represents the architectural requirements that a module named \"project.src.moduleB\" should not be imported by any module\nthat is a submodule of \"project.src.moduleA\", excluding \"project.src.moduleA\" itself.\n\n3) Evaluate your code against this rule\n\n```\nrule.assert_applies(evaluable)\n```\nThat's it!\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Test framework for software architecture based on imports between modules",
    "version": "4.0.1",
    "project_urls": {
        "Documentation": "https://zyskarch.github.io/pytestarch/latest",
        "Repository": "https://github.com/zyskarch/pytestarch",
        "issues": "https://github.com/zyskarch/pytestarch/issues"
    },
    "split_keywords": [
        "architecture",
        " test"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ac6e8b6079324672f03fd4b914345ecd2df95a04caf658faf4d7f7e7fa97d543",
                "md5": "c8e6a55d072f085917c8f50410167ffd",
                "sha256": "4dd5adc363b3e1fde72d4b34564f03e62f715cc5e38f1c3a347b0f1cc92168fe"
            },
            "downloads": -1,
            "filename": "pytestarch-4.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c8e6a55d072f085917c8f50410167ffd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 61982,
            "upload_time": "2025-08-08T12:54:42",
            "upload_time_iso_8601": "2025-08-08T12:54:42.818013Z",
            "url": "https://files.pythonhosted.org/packages/ac/6e/8b6079324672f03fd4b914345ecd2df95a04caf658faf4d7f7e7fa97d543/pytestarch-4.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "42a288b37e1133457c224155c29ae3619915977063e44fbf0d1780012aeb6a3e",
                "md5": "73b5d143e935ffffffd23a214efd885a",
                "sha256": "2f288eb8a8a818d3d89a45180d1756c4db2885a7a1281c4ac019665ed97db6b9"
            },
            "downloads": -1,
            "filename": "pytestarch-4.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "73b5d143e935ffffffd23a214efd885a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 42727,
            "upload_time": "2025-08-08T12:54:43",
            "upload_time_iso_8601": "2025-08-08T12:54:43.928738Z",
            "url": "https://files.pythonhosted.org/packages/42/a2/88b37e1133457c224155c29ae3619915977063e44fbf0d1780012aeb6a3e/pytestarch-4.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-08 12:54:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zyskarch",
    "github_project": "pytestarch",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pytestarch"
}
        
Elapsed time: 1.41435s