Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should I put tests when packaging python modules?

Tags:

I have a module that sits in a namespace. Should tests and data the tests rely on go in the namespace or in the top level where setup.py sites?

./company/__init__.py ./company/namespace/__init__.py ./company/namespace/useful.py ./company/namespace/test_useful.py ./company/namespace/test_data/useful_data.xml ./setup.py 

or

./company/__init__.py ./company/namespace/__init__.py ./company/namespace/useful.py ./test_useful.py ./test_data/useful_data.xml ./setup.py 

Does the question amount to whether tests should be installed or not?

like image 618
Stephen Paulger Avatar asked Mar 17 '11 15:03

Stephen Paulger


1 Answers

The Sample Project stores the tests outside the module.

The directory structure looks like this:

├── data │   └── data_file ├── MANIFEST.in ├── README.rst ├── sample │   ├── __init__.py │   └── package_data.dat ├── setup.cfg ├── setup.py └── tests     ├── __init__.py     └── test_simple.py 

Related: The Packing Guide: https://packaging.python.org/en/latest/

Hint: Don't follow the "The Hitchhiker's Guide to Packaging". It has not been updated since 2010!

(do not confuse both pages. The "The Hitchhiker’s Guide to Python" is a very solid book)

like image 159
guettli Avatar answered Oct 12 '22 23:10

guettli