For python unit tests, is the following a common naming convention?
MyProject/
run_ingest.py
tests/
run_ingest.py
Or is this too redundant? If so, what would be a better naming convention or directory structure to put testing code?
Having a directory called tests is correct but, as per my experience, the test scripts themselves are usually prefixed with test_
so in your case test_run_ingest.py
. Make sure to use underscore rather than -
as a separator in the names to avoid import problems. As for the structure, you'd also probably want to include __init__.py
files both to the top level and /tests
folder to simplify imports.
If you are new to unittest
this blog might be of interest.
Add a little bit to Alexander's answer. In test_run_ingest.py , write from run_ingest import *
, and when testing, cd to MyProject and type python3 -m unittest tests.test_run_ingest
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.