7

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.

Yuri Costa
  • 199
  • 9

4 Answers4

2

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.

JL Peyret
  • 10,917
  • 2
  • 54
  • 73
  • 1
    Wily does not look at the package or dependency/import structure, but just static analysis metrics. – danuker Aug 02 '21 at 14:27
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
Antash
  • 878
  • 6
  • 15
0

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

contramao
  • 51
  • 1
  • 2
0

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!

Parvez Khan
  • 537
  • 7
  • 15