Answer the question
In order to leave comments, you need to log in
Structure for storing unit tests in a Django (and not only) project?
Good day. I wondered about the coverage of code by unit tests. In python, I didn't really work with this before. Googling, I can not decide which option is correct (I doubt between the two).
Based on the n-th experience with Java, the following is practiced in toad projects:
src-|
-main
|-com.trolololo.foo
-test
|-com.trolololo.foo
project
|- app1
|- services
|- foo.py
|- bar
|- qwe.py
|- models.py
|- views.py
|- tests
|- test_models.py
|- test_views.py
|- services
|- test_foo.py
|- bar
|- test_qwe.py
project
|- app1
|- services
|- foo.py
|- foo2.py
|- bar
|- qwe.py
|- test_qwe.py
|- tests
|- test_foo.py
|- test_foo2.py
|- models.py
|- views.py
|- tests
|- test_models.py
|- test_views.py
Answer the question
In order to leave comments, you need to log in
flat>>>nested
if you really, really need to nest, then you can split a large file into files and put them in a folder with the name of the directory and add an empty __init__.py
project
|- app1
< вот такой фигни нет >
|- services
|- foo.py
|- bar
|- qwe.py
</ вот такой фигни нет >
< для такой фигни есть commands >
|-management
|-commands
|-__init__.py
|-my_command.py
</ для такой фигни есть commands >
|- models.py
|- views.py
|- tests
|-__init__.py
|- test_models.py
|- test_models_supermodel.py
|- test_views.py
|-test_commands_my_command.py
|-hugeapp
.....
|- tests
|-__init__.py
|- test_models <<dir как питоновский пакет
|-__init__.py
|- test_model1.py
....
|- test_model999.py
Probably here the essence is in the reuse of dzhangi applications. If you plan to distribute applications (at least between your projects), then the tests file / package should be kept inside the application folder. Direct analogy with templates.
If the tests are functional, that is, for the behavior of the entire project and / or a bunch of applications, then naturally there is a package in the root of the project and there are test modules.
But in general, for me personally, the tests folders in each app clutter up the project when it is large - it is difficult to look at the entire project tree. Therefore, I often make one package tests at the root of the project and inside I approximately repeat the project tree. Flies from cutlets separately, so to speak.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question