What is the optimal naming convention for test files in Python?

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)