Organization

A professional Python project maintains strict architectural separation between the source code and the test suite. This prevents testing artifacts from polluting the distribution package and forces the tests to import the source code exactly as an end-user would. Developers organize their tests within a dedicated directory, typically named tests/, located at the root of the project repository.

Within this directory, test files must adhere to strict naming conventions to facilitate automatic discovery by the testing framework. Files must begin with the prefix test_ or end with the suffix _test.py. Similarly, the individual testing functions within these files must begin with the word test_. This prefixing strategy allows the test runner to traverse the directory tree, identify all applicable testing logic, and execute it without requiring a manually maintained registry of tests.

Last updated on