When a python module has multiple subpackages, where should tests for features in those subpackages be placed?
I can see two ways it could be done:
test
folder in each subpackage and place its tests there.test
folder, placing the tests for each subpackage in the corresponding folder.However it's not clear which option should be preferred.
For a package foo
arranged like this:
foo/
__init__.py
bar.py
baz/
__init__.py
baz.py
Do I put the tests here?
foo/
__init__.py
bar.py
baz/
__init__.py
baz.py
test/
__init__.py
test_bar.py
baz/
__init__.py
test_baz.py
Or here?
foo/
__init__.py
bar.py
baz/
__init__.py
baz.py
test/
__init__.py
test_baz.py
test/
__init__.py
test_bar.py
There is a similar answer here:
https://stackoverflow.com/a/24266885/6529424
But it really comes down to preference/style or it depends on whatever framework you use to test your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With