I am developing a collection of Python packages/modules (no executables). What is the correct/best way to set up the file hierarchy for testing. I can think of two scenarios:
Scenario 1:
AllPackages/
package1/
module1-1.py
module1-2.py
package2/
module2-1.py
module2-2.py
tests/
package1/
test_module1-1.py
test_module1-2.py
package2/
test_module2-1.py
test_module2-2.py
Scenario 2:
AllPackages/
package1/
module1-1.py
module1-2.py
tests/
test_module1-1.py
test_module1-2.py
package2/
module2-1.py
module2-2.py
tests/
test_module2-1.py
test_module2-2.py
I am new to unittesting (I know I should have done it long ago) so I'm not sure which of these approaches is better and I'm looking for some advice from those which have more experience.
Thanks!
The 2nd scenario allows you to have pluggable packages and is used at least in Django framework (to mention some authority). If you use plain unittest
module, it has discover utility, which will find all the tests you have in your project folder no matter how you organized them, so the 2nd approach fits here too.
Scenario 1 is better, in my opinion. It makes things easier when you deploy, for example. You don't want to deploy test code, so you just omit the tests/
directory in your package. This approach is much cleaner.
Scenario 2 is messy; I don't see any advantage of mixing test code and production code in this way.
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