Is there any library like arch unit for Django?
Asked Answered
T

4

9

I've been searching for a library or tool to test my Django project architecture, check the dependencies, layers, etc. like Arch Unit for Java. But until now, I didn't find anything. I don't even know if it's viable doing these kinds of tests in Python/Django projects. I know that Django itself already checks for cyclic dependencies.

Tomtoma answered 18/3, 2021 at 13:34 Comment(1)
github.com/zyskarch/pytestarch is based on ArchUnitDabber
L
3

Check out what you can find under Python complexity metrics.

A tool called Wily may be of use. However, what counts as good practices will be very different for Java and Python.

Lots answered 19/3, 2021 at 23:45 Comment(1)
Wily does not look at the package or dependency/import structure, but just static analysis metrics.Gear
B
3

If you are looking for something simple yet powerful then I would recommend to explore pytestarch

You can find the install instructions here: https://pypi.org/project/pytestarch/

Also the official documentation can be referred from here: https://zyskarch.github.io/pytestarch/1.5.0/features/general/

Hope this help!

Bleb answered 21/8, 2023 at 10:46 Comment(0)
B
0

The closest that I know of is https://github.com/seddonym/import-linter

It's capable only of linting - as the name suggests - imports between modules so it has far fewer capabilities than ArchUnit, but I used it with great success in several clean/hexagonal architecture projects.

To use it to the full extent you need to wisely split your projects into modules so that the import statements "follow" (or rather "match") your designated architecture.

Some example of the rules that I often use:

[importlinter:contract:8]
name = Modules .core cannot depend on shared infrastructure
type = forbidden
source_modules =
  src.services.service1.modules.module1.core
  src.services.service2.modules.module1.core
  src.services.service2.modules.module2.core

forbidden_modules =
  src.shared.infrastructure


[importlinter:contract:3]
name = modules inside services shall be independent
type = independence
modules = 
  src.services.service1.modules.module1
  src.services.service2.modules.module1
  src.services.service2.modules.module2
Baram answered 14/6, 2022 at 5:58 Comment(0)
T
0

There is also pytest-archon. Its syntax is simpler than import-linter's and uses pytest instead of separate config files.

Thirzia answered 30/11, 2022 at 8:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.