Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does setuptools installs test dependencies on python setup.py test command

When I use the command python setup.py test, all of the documentation I've seen says setuptools will handle installing the testing dependencies. Where does it install them and are they deleted from the machine after the test suite runs? I've noticed none of the testing modules are actually installed into my virtual environment after this command completes.

I understand it takes all of the modules in the tests_require list and installs them somewhere but I'm not sure where, what it does with them afterward and why it does this. Also, is there any way to pass arguments to the command without using flags, like with a config file or something?

like image 644
Johnny Metz Avatar asked Jul 05 '26 21:07

Johnny Metz


2 Answers

Avoid python setup.py test and tests_require, it's crufty and is now deprecated.

That old feature just downloads the test deps to the project's setup directory, which is seldom what the developer wanted or expected to happen! That doesn't work well in a modern CI workflows with virtual environments, where you would want your dependencies installed to site-packages.

The recommended way to do it using setuptools these days is with an extras_require tag.. See here for an example.

like image 179
wim Avatar answered Jul 07 '26 12:07

wim


It installs them into an automatically-created subdirectory of the code base named .eggs as .eggs. That's because .eggs are designed to be importable from any location.

This will thus most likely not work in a modern environment because packages are not distributed as .eggs (which lost competition to .whls) so setuptools will have to build them from source (with bdist_egg). Which is likely to fail for many widely-used binary packages with nontrivial build requirements (not to mention the time needed and the fact that packages are not tested as .eggs, either, and may fail when packaged like this).


Instead, listing build requirements in requirements.txt and invoking pip install -r requirements.txt before the build seems to have become widespread practice. This does not make setup.py automatically buildable from source by pip though.

I tried to install them myself from setup.py but this proved to be fragile (e.g. if the user doesn't have write access to site-packages).

The best solution adopted by at least a number of high-profile projects seems to be to just make setup.py fail if they are not present. This is especially useful if the requirements are not Python but C libraries as setup.py doesn't know how to install these in the specific environment anyway. As you can see, this complements requirements.txt naturally.

like image 29
ivan_pozdeev Avatar answered Jul 07 '26 11:07

ivan_pozdeev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!