Python TDD Directory Structure

Is there a specific directory structure used for TDD in Python?

The textbooks talk about the content of the tests, but not about where to place them.

From pushing around Python Koans, suspect something like:

/project/main_program.py # This has main method, starts program /project/classes/<many classes>.py /project/main_test.py # This simply directs unittest onto tests, can use parameters fed to it to customise tests for environment /project/tests/<many tests>.py # to run tests, type "python -m unittest main_test.py" (into a terminal) # to run program, type "python main_program.py" 

Am I doing it right? Is there a good guide that teaches directory hierarchies for TDD? I heard that mixed code and test files are bad.

Literature:

+6
source share
2 answers

Based on your project, any style allows you

  • Separate implementation code from verification code
  • Easy to create new tests.
  • Run all tests in one operation (for example, to test regression)

Python koans / etc are just recommendations. After all, you want to support DRY with your unittests and be able to easily, intuitively, and intuitively check. Ultimately you decide your folder structure.

I feel that you focus too much on satisfying the agreement, not on satisfying your project.

+4
source

There are two main options: in the "test" (or "test") directory of the top level or in the "test" directories of your package at each level. The advantage of the first is that it is easy to carry out both single tests and other tests. The latter has the advantage that it makes it easy to run tests with the installed version of the code and is recommended in this blog post , which describes the basic structure that works well for Python projects.

At the end of the day, it is important to make them easy to find and run.

+1
source

Source: https://habr.com/ru/post/911597/


All Articles