Data files for tests
eryksun ()
eryksun at gmail.com
Sun Mar 27 19:48:19 EDT 2011
On Sunday, March 27, 2011 7:33:22 PM UTC-4, eryksun () wrote:
> On Sunday, March 27, 2011 7:07:33 PM UTC-4, Steven D'Aprano wrote:
> > I have a package with some tests. The tests are not part of the package
> > itself, so I have a laid out my files like this:
> >
> >
> > src/
> > spam/
> > __init__.py
> > other-files.py
> > test_spam.py
> >
> >
> > Some of the tests depend on external data files. Where should I put them?
> > In the same directory as test_spam?
>
> Including data files and accessing them via the resource management API:
>
> http://packages.python.org/distribute/setuptools.html#including-data-files
For example, if test_spam is in a separate package:
setup.py
src/
spam/
__init__.py
other-files.py
test_spam/
__init__.py
test_spam.py
data/
test_data.dat
setup.py:
from setuptools import setup, find_packages
setup(
# ...
packages = find_packages('src'), # include all packages under src
package_dir = {'':'src'}, # tell distutils packages are under src
package_data = {
# include any *.dat files found in the 'data' subdirectory
# of the 'test_spam' package:
'test_spam': ['data/*.dat'],
}
)
More information about the Python-list
mailing list