I wrote some code that I would like to share, and I would like to follow the best practices in creating/maintaining it's structure. I will host the code on BitBucket, and now I'm thinking about how I should organize it. Is this a good structure?
project_name/
lib/
test/
README
So, this will have the source in lib, and the tests in test. Is this how it's done in Python projects? This is the structure I saw was the most used with Ruby projects. Also, when I run the unit tests, is it considered good practice to do it like this:
set PYTHONPATH=`pwd`/lib
python test/a_test.py
Your app is stored as a directory structure that you can clone using Git. Each Package, Module and Form consists of files and directories within this structure.
If you're using the PyCharm IDE, you can run unittest or pytest by following these steps: In the Project tool window, select the tests directory. On the context menu, choose the run command for unittest . For example, choose Run 'Unittests in my Tests…'.
The approach I've come to like is the following:
doctest
is what you want, because it can double as "bare-bones" documentation
(when you document the tests and include some commentary on what it's doing).
You can either use doctest to use tests in the docstrings of your code or
keep the tests in some separate .txt files.You can integrate doctest by extending the setup
command with an appropriate cmdclass=...
entry in the setup.py file. See this example (CouchDB setup)
for one solution that integrates testing in setup.py. (It uses separate files that
have both the tests and the actual documentation, which is also a possibility).
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