For a file module.py, the unit test should normally be called test_module.py, following Pythonic naming conventions.
There are several commonly accepted places to put test_module.py:
- In the same directory as
module.py. - In
../tests/test_module.py(at the same level as the code directory). - In
tests/test_module.py(one level under the code directory).
I prefer #1 for its simplicity of finding the tests and importing them. Whatever build system you’re using can easily be configured to run files starting with test_. Actually, the default unittest pattern used for test discovery is test*.py.