Where do the Python unit tests go? -
if you're writing library, or app, unit test files go?
it's nice separate test files main app code, it's awkward put them "tests" subdirectory inside of app root directory, because makes harder import modules you'll testing.
is there best practice here?
for file module.py
, unit test should called test_module.py
, following pythonic naming conventions.
there several commonly accepted places put test_module.py
:
- in same directory
module.py
. - in
../tests/test_module.py
(at same level code directory). - in
tests/test_module.py
(one level under code directory).
i prefer #1 simplicity of finding tests , importing them. whatever build system you're using can configured run files starting test_
. actually, default unittest
pattern used test discovery test*.py
.
Comments
Post a Comment