[Python-ideas] Official site-packages/test directory
Barry Warsaw
barry at python.org
Fri Jan 26 10:02:24 EST 2018
Guido van Rossum wrote:
> IIUC another common layout is to have folders named test or tests inside
> each package. This would avoid requiring any changes to the site-packages
> layout.
That's what I do for all my personal code. Yes, it means the test
directories are shipped with the sdist, but really who cares? I don't
think I've had a single complaint about it, even with large-ish projects
like Mailman. I can see you wanting to do something different if your
project has truly gargantuan test suites, but even with 100% coverage
(or nearly so), I think size just isn't usually a big deal.
In another message, Giampaolo describes being able to run tests with -m
psutil.test. That's a neat idea which I haven't tried. But I do think
including the tests can be instructive, and I know that on more than one
occasion, I've cracked open a project's test suite to get a better sense
of the semantics and usage of a particular API.
Finally, I'll disagree with pytest's recommendation to not put
__init__.py files in your test directories. Although I'm not a heavy
pytest user (we use it exclusive at work, but I don't use it much with
my own stuff), having __init__.py files can be useful, especially if you
also have test data you want to access through pkg_resources, or now,
importlib_resources (importlib.resources in Python 3.7).
Cheers,
-Barry
More information about the Python-ideas
mailing list