I am looking for an optimal naming convention for python test files that ease the usage of different test frameworks (unittest, note, pyunit, ...) and also that is friendly with test auto-discovery for these tools.
I just want a clear set of recomandation that would require minimal configuration for tools.
test
or tests
? I know, I have too much time :)
Don't call the directory test
or it will conflict with the built-in test
package.
The naming conventions are defined in PEP 8 . See the 'Naming Conventions' section. Underscores are better than hyphens!
The layout of your package is a bit more flexible. I tend to do the following:
package
|-- package
| |-- __init__.py
| `-- <etc>
|-- tests
| `-- <etc>
|-- setup.py
|-- README
|-- LICENCE
`-- <etc>
This keeps the tests separate from the package itself. Installing the package using setup.py can install just the source, which keeps people's interpreters tidy. The tests are there for developers that need them when they get the package source.
You should look at The Hitch Hiker's Guide to Packaging for more info on Python packages.
It will depends of the tool you're using to run your tests.
If you're using nosetest , the philosophy used to detect test is pretty simple :
If you're using py.test , the conventions are pretty open too .
About the "where to put test" question, personnaly, I prefer to store tests in a subdirectory in each package to be sure to not forgot to run/touch the tests when someone edit the code ;)
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.