[Tutor] directory structure with tests?

Mats Wichmann mats at wichmann.us
Wed Mar 6 17:38:19 EST 2019


On 3/6/19 3:17 PM, James Hartley wrote:
> It is preferable to sprinkle tests files throughout the directories of a
> project, or coalesce all tests in a test directory?

"It depends".

There are people who have strong opinions.

If you're going to use conventions like naming the test for the
functionality in foo.py as test_foo.py, it makes sense for the two to be
nearby each other. That can be the same directory, or a subdirectory (a
harness like Py.Test will find files named test_* and assume they're
tests whichever place they're in). Very large projects may well split
tests into more subdirectories based on their purpose or usage.

On the other hand, if your project is going to be turned into a package,
you might want to keep the tests in a separate directory, as it may be
somewhat easier to select what goes into the package if they're not
sprinkled together.

You may also end up handling unit tests and integration tests differently.

How's that for a definitive answer?  :)



More information about the Tutor mailing list